CSS Layout Model
The layout model is the same as the box model, which is the most basic and core concept of CSS.
But the layout model is based on the box model. It's also different from the CSS layout style or CSS layout template we used to say. Suppose that the layout model is Ben. Then the CSS layout template is the end. is a form of outward manifestation.
CSS consists of 3 main layout models. In English: Flow, Layer, and Float.
In the Web page. There are three layout models of elements:
1. Flow model
2. Floating model (float)
3. Layers Model (layer)
Flow Model
First of all, the flow model , flow is the default page layout mode. This means that the HTML page elements in the default state of the Web page are distributed according to the flow model.
The flow layout model has 2 typical characteristics:
1th. block elements are spread vertically from top to bottom within the included elements , because, by default, the width of the block element is 100%. As a matter of fact. The block elements occupy the position in the form of rows. As in the right-hand code editor, the three-block scholar-label (div,h1,p) width is displayed as 100%.
2nd, under the flow model. Inline elements are displayed horizontally from left to right within the included elements. (inline elements are not like blocky elements so overbearing exclusive line)
Floating model
Block elements So overbearing is the exclusive line, suppose today we want to let two blocks of the top-side display, how to do? Do not worry, set the element float will be able to achieve this desire.
No matter what element is not floating by default, but can be defined as a floating CSS, such as Div, p, table, IMG and other elements can be defined as floating.
For example, 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 at the same time right float can also be implemented on a line display.
div{ width:200px; height:200px; BORDER:2PX Red Solid; float:right;}
And a little friend asked. Set two elements one left and right can I display a line? Of course you can:
div{ width:200px; height:200px; BORDER:2PX red Solid;} #div1 {float:left;} #div2 {float:right;}
What is a layer model?
What is a layer layout model? The layer layout model is like a popular layer editing feature in Photoshop, the image software. Each layer can precisely position the operation, but in the web design area, because the Web page size is active. The layer layout was not hot enough.
However, it is convenient to use the layer layout locally on the Web page. Let's take a look at the layer layout in HTML.
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)
Layer model--absolute positioning
Assuming that you want to set absolute positioning for an element in the layer model, you need to set Position:absolute(for absolute positioning), which drags the element out of the document stream and uses the left, right, top, and bottom properties relative to its The closest parent that has a positional property is an absolute positioning block. Assume that there is no such inclusion block, relative to the body element, that is, relative to the browser form .
The following code enables the DIV element to move 100px to the right relative to the browser form, moving the 50px down.
div{ width:200px; height:200px; BORDER:2PX Red Solid; Position:absolute; left:100px; top:50px;} <div id= "Div1" ></div>
Effects such as the following:
Layer model--relative positioning
Assuming that you want to set the relative positioning of the layer model for an element, you need to set position:relative(for relative positioning), which determines where the element is offset 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 the direction and amplitude of the move is determined by the left , right, top, and bottom properties relative to the previous position , and the position before the offset remains fixed .
For example, the following code implements moving down 50px relative to the previous position. Move 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 "?
We can do an experiment. Add a span tag after the Code Editor DIV tag to mark and write some text in the span tag. For example, the following code:
<body> <div id= "Div1" ></div><span> offset before the position remains motionless, overwriting the previous Div without the position before the offset </ Span></body>
:
Can be clearly seen from it. Although the div element is offset from where it was once. The position of the DIV element is retained, so the span element behind it is displayed behind the position of the DIV element.
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 form within the screen ) itself. Because the view itself is fixed. It does not change depending on the scroll bar of the browser form, unless you move the screen position of the browser form on the screen, or change the display size of the browser form, so the anchored element is always located somewhere in the browser Form view and is not affected by the flow of the document. This is the same as the Background-attachment:fixed property feature. The following code can 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>
Relative combined with absolute
The small partners learned the absolute positioning of the 12-6 bars by using the position:absolute ability to implement the set element relative to the browser (body) setting after positioning. Have you ever wondered if you could be positioned relative to other elements? The answer is yes. Of course I can.
Use Position:relative to help, but you must abide by the following specifications:
1, the element must be relative positioning elements of the predecessor element:
<div id= "Box1" ><!--the element that is positioned-- <div id= "Box2" > relative element positioning </div><!--relative positioning elements-->< /div>
It can be seen from the above code that BOX1 is the parent element of Box2 (the parent element is, of course, the predecessor element).
2, the elements of the positioning must be increased position:relative;
#box1 { width:200px; height:200px; }
3, positioning elements increase position:absolute, you can use top, bottom, left, right to offset positioning.
#box2 { position:absolute; top:20px; left:30px; }
This allows the box2 to be positioned relative to the parent element box1 (note that the reference is not a browser and can be set freely).
CSS Layout model