Regarding the issue of li floating! Solve_html/css_WEB-ITnose
First, take the picture above,
Add a picture to li, and then set the first float, the effect is as above,,,, but,,
After adding width and height to li, it becomes like the above, Why is this, please explain?
Reply to discussion (solution)
If you want to implement two columns, then ul sets the width of two li, and all li float Just
li is a block tag, which is meant to occupy one line. For the first one, you used float:left, which floats to the left to make way for the right position. The second li takes up the remaining space. , the second one does not float, it just occupies one line, so the last one starts on another line. The second case: li does not float, each occupies one line, so they all need to be wrapped.
After float is set, it breaks away from the normal flow, and the second li element moves up
After li sets the width, because #one has the same width as the following li, it is equivalent to the second li block-level element The leftmost part is occupied by #one, that is, the width of the first line is full, and the content in it can only be wrapped and displayed on the second line; when the width is not set, the width of #one is only the width of the a character, and the second The default width of each li is 100% UL width
After the float is set, it breaks away from the normal flow, and the second li element moves up
After the li width is set, because #one and the following The li width is the same, which is equivalent to the leftmost part of the second li block-level element being occupied by #one, that is, the first line of width content is full, and the content in it can only be wrapped and displayed on the second line; and when the width is not set , the width of #one is only the width including the a character, and the width of the second li defaults to 100% UL width
I understand the first one, but I still don’t know why I set the width. , its effect is different, (because #one has the same width as the following li, which is equivalent to the leftmost part of the second li block-level element being occupied by #one) I can't understand this sentence, please give me an answer! Thank you
After float is set, it breaks away from the normal flow, and the second li element moves up
After li sets the width, because #one has the same width as the following li , which is equivalent to the leftmost part of the second li block-level element being occupied by #one, that is, the first line of width content is full, and the content in it can only be wrapped and displayed on the second line; and when the width is not set, #one's The width is only the width including the a character. The second li width defaults to 100% UL width
I understand the first one, but I still don’t know why it has the effect after setting the width. It's different, (because #one has the same width as the following li, which is equivalent to the leftmost part of the second li block-level element being occupied by #one) I can't understand this sentence, please give me an answer! Thank you
When the browser renders, the floating elements are superimposed on the normal flow elements. The width of the second li element is only 120px and the height is adaptive. The width of #one is also 120px. When it floats to the left end, the content of the second li element will be positioned close to the right end of #one. If there is not enough space, it can only go down. If you set the width of the second li element to 120px, you may understand
More often than not, there is no need to worry too much about why this is the case, because doing so itself has compatibility issues. For example, the effect of text surrounding images is inconsistent in different browsers. There is no solution. The only way is to avoid similar layouts when doing it
Another example, two block levels If elements want to be displayed in the same row, many people will use the method of setting float first and pushing the second one up. However, this method will produce inexplicable white gaps under IE6/7 when certain conditions are met, and there is no way to solve it. Floats can only be set uniformly
If you really want to know why this is the case, I think you have to understand it from the underlying rendering mechanisms of major browsers. Even if you understand it, you will avoid similar layouts.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to write an algorithm to find the least common multiple in Python? The least common multiple is the smallest integer between two numbers that can divide the two numbers. In mathematics, solving the least common multiple is a basic mathematical task, and in computer programming, we can use Python to write an algorithm for solving the least common multiple. The following will introduce the basic least common multiple algorithm and give specific code examples. The mathematical definition of the least common multiple is: If a is divisible by n and b is divisible by n, then n is the least common multiple of a and b. To solve the minimum

HTML, CSS and jQuery: Making a button with a floating effect requires specific code examples. Introduction: Nowadays, web design has become an art form. By using technologies such as HTML, CSS and JavaScript, we are able to add various aspects to the page. Such special effects and interactive effects. This article will briefly introduce how to use HTML, CSS and jQuery to create a button with a floating effect, and provide specific code examples. 1. HTML structure First, we need to

li is an element in the HTML markup language and is used to create lists. li represents a list item, which is a child element of ul or ol. The role of the li tag is to define each item in the list. In HTML, the li element is usually used with the ul or ol element to create an ordered or unordered list. Unordered lists use the ul element, and list items are represented by the li element, while ordered lists use the ol element, also using li Element representation.

In HTML, the full English name of li is "list item", which means "list item". It is an element tag that defines a list item. The syntax is "<li>list item content</li>"; "<li>" tag Available in ordered list "<ol>" and unordered list "<ul>".

Is there any method to clear floats? Specific code examples are required. In web page layout, floats are a common layout method that allows elements to break away from the document flow and be positioned relative to other elements. However, a problem often encountered when using floating layout is that the parent element cannot wrap the floating element correctly, causing the page to have a disordered layout. Therefore, we need to take measures to clear the float so that the parent element can wrap the floated element correctly. There are many ways to clear floats. The following will introduce several commonly used methods and give specific code examples.

Numpy is a well-known scientific computing library in Python, which provides rich functions and efficient computing methods for processing large multi-dimensional arrays and matrices. In the world of data science and machine learning, matrix inversion is a common task. In this article, I will introduce how to quickly solve the matrix inverse using the Numpy library and provide specific code examples. First, let's introduce the Numpy library into our Python environment by installing it. Numpy can be installed in the terminal using the following command: pipinsta

Title: Use C language programming to implement the greatest common divisor solution. The greatest common divisor (Greatest Common Divisor, GCD for short) refers to the largest positive integer that can divide two or more integers at the same time. Solving for the greatest common divisor can be very helpful for some algorithms and problem solving. In this article, the function of finding the greatest common divisor will be implemented through C language programming, and specific code examples will be provided. In C language, you can use the Euclidean Algorithm to solve the maximum

How to remove the li default style in css: 1. Create an HTML sample file; 2. Add the li tag content; 3. Set the "list-style-type" attribute to "none" in css to remove the li default style.
