CSS Layout Model
- Mobile (flow)
- Floating type (float)
- Layers Model (layer)
- Characteristics of the Flow model
- Block elements are spread vertically from top to bottom within the containing element, because, by default, the width of the block element is 100%. In fact, a block element occupies a position in the form of a row.
- In a flow model, inline elements are displayed horizontally from left to right within the containing element in which they are located.
- Block elements So overbearing is the exclusive line, if now we want to let two blocks of the top-side display, how to do? Do not worry, set the element floating can realize this desire.
- Any element cannot float by default, but it can be defined as a floating CSS, such as Div, p, table, IMG, and so on, which can be defined as floating. The following code enables two DIV elements to be displayed on one line.
- div{
width:200px;
height:200px;
BORDER:2PX Red Solid;
Float:left;
}
<div id= "Div1" ></div>
<div id= "Div2" ></div>
- Of course you can also set two elements to the right float can also be implemented on a line display .
- div{
width:200px;
height:200px;
BORDER:2PX Red Solid;
Float:right;
}
- And a small partner asked, set two elements one to the left can you implement a row display? Of course:
- div{
width:200px;
height:200px;
BORDER:2PX Red Solid;
}
#div1 {float:left;}
#div2 {float:right;}
- How to position HTML elements precisely in a Web page, like a layer in the image software Photoshop, allows for precise positioning of each layer. CSS defines a set of positioning (positioning) properties to support the layer layout model.
- There are three forms of the layer model:
1. Absolute positioning (position:absolute)
2. Relative positioning (position:relative)
3, fixed positioning (position:fixed)
- Absolute positioning
- If you want to set absolute positioning in the layer model for an element, you need to set Position:absolute (for absolute positioning), which will drag the element out of the document stream.
- The left, right, top, and bottom properties are then used for absolute positioning relative to the parent containing block that has the location property closest to it.
- If no such inclusion block exists, then relative to the body element, that is, relative to the browser window.
- The following code can implement a DIV element to move to the right of 100px relative to the browser window and move the 50px down.
- div{
width:200px;
height:200px;
BORDER:2PX Red Solid;
Position:absolute;
left:100px;
top:50px;
}
<div id= "Div1" ></div>
- The effect is as follows:
- relative positioning
- If you want to set relative positioning in the layer model for an element, you need to set position:relative (for relative positioning).
- It determines the offset of an 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 the element floats like a layer.
- Then moving relative to the previous position, the direction and amplitude of the move are determined by the left, right, top, bottom properties, and the position before the offset is retained.
- The following code is implemented to move down 50px relative to the previous position, moving 100px to the right;
#div1 {
width:200px;
height:200px;
BORDER:2PX Red Solid;
position:relative;
left:100px;
top:50px;
}
<div id= "Div1" ></div>
- :
- What is the "position before offset"?
- You can do an experiment with the following code:
<body>
<div id= "Div1" ></div><span> position before offset is still not covered before the previous Div has no offset before the position </span>
</body>
- :
- It is obvious from this that although the DIV element has an offset from the previous position, the DIV element's previous position remains,
- So the later span element is displayed behind the DIV element's previous position.
- 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,
- As a result, fixed-positioned elements are always located somewhere in the view in the browser window and are not affected by the flow of documents.
- This 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.
#div1 {
width:200px;
height:200px;
BORDER:2PX Red Solid;
position:fixed;
left:100px;
top:50px;
}
<p> text-Text text-text-text-text-text-text text-text-text-text text-text-text-text-text-text-text-text-text-text-text-text text-text text-Text textual text text </p>
....
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
CSS Layout model