There are three kinds of positioning mechanisms in CSS: normal flow, floating, absolute positioning. (default to normal stream)
Change document flow: Display:inline-block; (Support to IE8 and above)
1-Anonymous block box:
< Div > Hi there! < P > Lio Ali! </ P > </ Div >
This piece of "Hello", belongs to the anonymous block box because it is not associated with a specially defined element.
2-relative positioning
The relative positioning of an element is positioned relative to its original position.
<!DOCTYPE HTML><HTML> <Head> <title>CSS Bug test</title> <MetaCharSet= "Utf-8"> <styletype= "Text/css">. Box-left{Display:Inline-block;width:50px;Height:50px;Background-color:Red; }. Box-middle{position:relative;Top:10px; Left:20px;Display:Inline-block;width:50px;Height:50px;Background-color:Green; }. Box-right{Display:Inline-block;width:50px;Height:50px;Background-color:Pink; } </style> </Head> <Body> <Divclass= "Box-left"></Div> <Divclass= "Box-middle"></Div> <Divclass= "Box-right"></Div> </Body></HTML>
When the element is positioned relatively, it will occupy its original position regardless of whether it has a top and left value set, or whether it is moving or not, and may overwrite other elements after moving.
3-Absolute positioning
Concept: Unlike relative positioning, the position of absolute positioning is independent of the document flow and therefore does not occupy space. Other elements in the normal document stream are not present.
Test: The code as shown on the relative positioning code, the only difference is to put position:relative; Replaced by Position:absolute;
Relative positioning |
Absolute positioning |
. box-middle{ position:relative; top:10px; left:20px; Display:inline-block; width:50px; height:50px; Background-color:green; } |
. box-middle{ Position:absolute; top:20px; left:20px; Display:inline-block; width:50px; height:50px; Background-color:green; } |
4-Fixed positioning
Support to IE7 above, 7 part support
5-Floating
Master CSS Advanced Web Standard Solution-visual format model-positioning model