Float attribute definition: In which direction the element floats
The default value is none.
Note: a floating element generates a block-level box, regardless of its own elements.
I. float syntax-TOP
Float often follows the attribute values left, right, and none.
Float: none
Float: left Float
Float: right Float to the right
Float syntax:
Float: none | left | right
Parameter value:
None: The object is not floating.
Left: The object is floating on the left.
Right: The object is floating on the right.
HTML code:
The code is as follows: |
|
<Body> <Div class = "main"> <Div class = "d" id = "d1"> box 1 </div> <Div class = "d" id = "d2"> box 2 </div> <Div class = "d" id = "d3"> Box 3 </div> <Div class = "d" id = "d4"> Box 4 </div> </Div> </Body> |
1. When all the sibling elements are floating elements, the height of the parent element will be zero if there is no custom width.
Css style:
The code is as follows: |
|
. Main { Border: 1px solid; } . D { Border: 1px solid red; Width: 50px; Height: 50px; Float: left; } |
2. The floating element will jump to the next row if there is not enough space in the row.
Css style:
The code is as follows: |
|
. Main { Border: 1px solid; Width: 130px; } . D { Border: 1px solid red; Width: 50px; Height: 50px; Float: left; } |
3. Floating elements are separated from text streams.
Ccs style:
The code is as follows: |
|
# D1 { Float: left; } |
Ss floating summary-TOP
We need to distinguish the text content from the text content to the left (text-align: left) to the right (text-align: right) style. Floating only sets the left-to-right floating style for html tags. Float floating style does not depend on the middle (floating center) style. If you need to center the label object, we will Center the text in the css layout to give you a detailed introduction (css margin ). Remember to use float: right for float to the right and float: left for float to the left.