In a Web page, elements have three layout models:
1. Flow model
2. Floating model (float)
3. Layers Model (layer)
1. Mobile model (flow)
The default page layout mode.
Two typical characteristics of a flow layout
1. The block element will extend the distribution vertically from the top two in the containing element, and by default, the width of the block element is 100%.
In fact, block elements occupy positions in the form of rows.
2. In the flow model, the inline elements are displayed horizontally from left to right within the containing element (inline elements are not as fast as the top-level monopoly line)
2. Floating model (float)
Enables two block-loaded elements to be displayed side-by
Float:left;
3. Layer model has advantages in local use of Layer model in Web page
1. Absolute positioning (Position:absolute)
2. Relative positioning (position:relative)
3. Fixed positioning (position:fixed)
1. Absolute positioning (Position:absolute)
If you want to set absolute positioning for an element in the layer model, you need to set Position:absolute (for absolute positioning), which will drag elements out of the document stream and use left, right, top, The bottom property is absolutely positioned relative to its closest parent containing block with a positional property. If no such inclusion block exists, then relative to the body element, that is, relative to the browser window.
position:absolute;left:100px;//on the left 100pxtop:50px;//50px
2 relative positioning (position:relative)
If you want to set relative positioning in the layer model for an element, you need to set position:relative (for relative positioning), which determines the offset of the element in the normal document stream through the left, right, top, and bottom properties. Relative positioning is done by first generating an element in static (float) mode, and then moving relative to the previous position, the direction and amplitude of the move is determined by the left, right, top, and bottom properties. The position before the offset is left motionless.
3. Layer Model fixed positioning
Fixed: Represents a pinned position, similar to the absolute anchor type, but its relative movement coordinates are the view ( the page window within the screen ) itself. Because the view itself is fixed, it does not change with the scroll bars of the browser window, unless you move the screen position of the browser window on the screen, or change the display size of the browser window, so the anchored element is always somewhere in the view in the browser window , is not affected by the flow of documents, which is the same as the Background-attachment:fixed property feature. The following code enables you to move the 100px to the right relative to the browser view and move the 50px down. And the position is fixed when you drag the scroll bar.
Example: Open the Web page in the lower right corner of the hate ads
An example based on absolute and relative
1 <!DOCTYPE HTML>2 <HTML>3 <Head>4 <MetaCharSet= "Utf-8">5 <title>Untitled Document</title>6 <styletype= "Text/css">7 Div{8 Border:2px solid Red;9 }Ten #box1{ One width:200px; A Height:200px; - /*Positioning child elements*/ - position:relative; the } - #box2{ - /*offset positioning using Top,left (the Reference object is anywhere)*/ - position:Absolute; + Top:50px; - Left:30px; + } A at </style> - </Head> - - <Body> - <DivID= "Box1"> - <DivID= "Box2">Relative reference element positioning</Div> in </Div> - </Body> to </HTML>
CSS Layout model