In the CSS layout, when it comes to positioning, you have to float, and the floating box moves left or right until its outer edge touches the containing box or another floating
The border of the box. Because the float box is not in the normal flow of the document, the Block box in the normal flow of the document behaves as if the floating box does not exist.
Definition and usage of a float property
Float Property: Set element float
Possible values:
None does not float, within the document flow, the default
Left floating, out of document flow
Right float, out of document flow
Inherit Specifies that the value of the float property should be inherited from the parent element.
The Float property defines the direction in which the element floats. Historically this attribute has always been applied to images, so that text surrounds the image, but in CSS, any
Elements can float. A floating element generates a block-level box, regardless of its own element. If a floating non-replacement element is specified, specify an explicit
Otherwise, they will be as narrow as possible. If there is only a small amount of space on top of a row for floating elements, then this element jumps to the next line, which
a process will persist until a row has enough of space.
We use illustrations and examples to understand the floating of elements:
(1) Illustration and effect of three non-floating elements:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
When the element is not floating, since we are using a DIV element that is a block-level element, we see three elements arranged sequentially below the element.
Instead of the next element arrangement.
(2) The diagram and effect of the first element floating to the left:
rewrite the code that floats the first element to the left:
#div_1 {background-color: #00FF00; width:200px;height:100px;float:left;}
When element 1 floats to the left, it is out of the document stream and moves to the left until its left edge touches the left edge of the containing box. Because it is no longer in the document
Stream, so it does not occupy space, actually covers the element 2, so that element 2 disappears from the view.
(3) The diagram and effect of the first element floating to the right:
rewrite the code that floats to the right of the first element:
#div_1 {background-color: #00FF00; width:200px;height:100px;float:right;}
When you float element 1 to the right, it moves out of the document stream and shifts to the right until its right edge touches the right edge of the containing box.
(4) Set the diagram and effect that all three elements are floating to the left:
Rewrite the code that all three elements are floating to the left:
#div_1 {background-color: #00FF00; width:200px;height:100px;float:left;} #div_2 {background-color: #FFFF00; width:200px;height:100px;float:left;} #div_3 {background-color: #FF0000; width:200px;height:100px;float:left;}
If you move all three boxes to the left, the box 1 floats to the left until it touches the containing box, and the other two boxes float to the left to touch the previous floating box.
(5) If the inclusion box is too narrow to accommodate the three floating elements arranged horizontally, the other floating blocks move down until there is enough space:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
(6) If the height of the floating elements is different, then they may be "stuck" by other floating elements when they move down:
code that overwrites the height of the first element:
#div_1 {background-color: #00FF00; width:200px;height:150px;float:left;}
So we'll see in the second instance that the floating element obscures the area of the document flow, so what do we do to see the contents of element 2? Under
We'll solve this problem: use the Clear property.
Two clear properties
Definition and usage of floating purge
The Clear property specifies which side of the element does not allow other floating elements. In CSS1 and CSS2, this is done by automatically clearing the elements (that is, setting the
The element of the clear attribute) increases the upper margin implementation. In CSS2.1, the clearance space is increased above the outer margin of the element, and the margin itself does not change
Change. Either way, the end result is the same, and if the declaration is left or right cleared, it causes the element's Sisu border boundary to just float on that side.
Below the boundary of the lower margin of the vegetarian.
Possible values
Left does not allow floating elements on the side.
Right does not allow floating elements on the left side.
The both does not allow floating elements on both sides of the left side.
None default value. Allows floating elements to appear on both sides.
Inherit specifies that the value of the clear property should be inherited from the parent element.
We use illustrations and examples to understand the clear floating of elements:
Example: First look back at the effect of the instance (2), we set the second element to have the clear floating element property:
#div_2 {background-color: #FFFF00; width:200px;height:100px;clear:left;}
Combination of three floats and clear float
let's look at an example:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
We see from the results that the floating elements are not incorporated into the entire document flow of our edits, and from a layout point of view, the text content should be immediately followed by the area block
is arranged on a different line, but it does not achieve the desired effect.
How do I let floating elements fit into the entire document flow layout?
in practice, we find a feasible way to add a div to the area block of the floating element and set the div to clear the floating property, which
The sample floating element is actually present in the document flow.
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
Look at the effect:
CSS Basic Learning 18: CSS layout floating