Deep understanding of CSS positioning full understanding of relative and absolute positioning of CSS positioning, deep understanding of css
In fact, both the standard stream and floating stream are very understandable, that is, positioning is not very easy to understand, especially relative and absolute positioning. Many of the first students are hard to distinguish. Therefore, Mr. Xiaoqiang shared his learning on CSS positioning.
Based on our previous study, our webpage layout method is as follows:
1. Standard stream (most stable)
2. Floating stream (second to float)
3. Locate the stream (final stability)
Positioning is completely out of the standard stream layout.
In fact, both the standard stream and floating stream are very understandable, that is, positioning is not very easy to understand, especially relative and absolute positioning. Many of the first students are hard to distinguish. Therefore, Mr. Xiaoqiang shared his learning on CSS positioning.
We know that positioning is used together with azimuth nouns to adjust positions. Most of them use top, left, bottom, and right.
First, let's look at the classification of positioning:
1. absolute positioning of absolute
Position: absolute;
Absolute positioning is a relatively large part of relative positioning. Definitely find out what features are there. Here, Mr. Xiaoqiang will give you a summary.
1. If no parent box is located
Then, the box, coupled with absolute positioning, is based on the top left corner of the browser as the origin, and all moves are also based on the origin to move.
Case
After Preview
2. If there is a parent box but the parent box is not located, the result will not change. The box will still start with the top left corner of the browser.
After Preview
3. If there is a parent box and the parent box is positioned, the absolute positioning will be aligned with the origin in the upper left corner of the parent box.
Effect:
4. Absolute positioning has a very important feature, so it will not occupy the position and be completely out of the standard stream, so it will rise and there will be a standard stream occupying the back side of it. 2. relative)
Position: relative
Relatively simple positioning. Whether there is a parent box or not, it is based on its own upper left corner.
Also, it occupies the position, that is, there are other boxes, which will be placed below.
3. Fixed Positioning
Position: fixed
Fixed positioning is also relative to the browser, which is fixed to a location in the browser. (Ie6 does not support fixed positioning and can only be resolved separately)
Fixed positioning, not occupying the position, completely out of the standard stream.
4. Static location
Position: static
It is almost the same as a standard stream, with no special positioning and location.
5. Stacked order:
Z-index: Numeric Value;
The larger the value, the closer the box is to the top. Note that the unit cannot be added to the value.
. One {z-index: 10 ;}
Summary:
For positioning, static positioning and relative positioning are available, while absolute positioning and fixed positioning are available. This is very important and has a great impact on the layout of standard streams.
We must remember that the sub-level is absolute, and the parent level is relative. This is the most suitable Layout Concept for our layout.
Absolute and relative positioning in css
About position attribute
Position
Open classification: HTML, CSS, WEB standards, and WEB design
Bottom right top z-index left
Position version: CSS2 compatibility: IE4 + NS4 + inheritance: None
Syntax:
Position: static | absolute | fixed | relative
Valid value:
Static: default value. No special positioning. Objects follow HTML positioning rules.
Absolute: drag an object out of the Document Stream and use left, right, top, bottom, and other attributes to absolutely locate the parent object with the most positioning settings relative to the object closest to it. If such a parent object does not exist, it is based on the body object. Its stack is defined by the z-index attribute.
Fixed: not supported. Object positioning follows the absolute (absolute) method. But comply with some rules
Relative: objects cannot be stacked, but will be offset in normal document streams based on left, right, top, bottom, and other attributes.
Note:
How to locate the retrieved object.
Setting this attribute value to absolute will drag the object out of the normal Document Stream and definitely locate it without considering the layout of its surrounding content. If other objects with different z-index attributes occupy a given position, they will not affect each other, but will stack at the same position. At this time, the object does not have an external patch (margin), but it still has an internal patch (padding) and a border (border ).
To activate the absolute (absolute) Positioning of an object, you must specify at least one of the left, right, top, and bottom attributes and set this attribute value to absolute. Otherwise, the property will use their default value auto, which will cause the object to follow the normal HTML layout rules and be presented immediately after the previous object.
Setting this property value to relative will keep the object in a normal HTML stream, but its position can be offset based on its previous object. The text or objects after the relative (relative) positioning objects occupy their own space and do not overwrite the natural space of the objects to be located. In contrast, the text or object after an absolute (absolute) Positioning object occupies its natural space before it is dragged away from the normal document stream. Placing an absolute (absolute) Positioning object outside the visible area will cause the scroll bar to appear. The scroll bar does not appear when the relative (relative) Positioning object is placed outside the visible area.
The content size is determined based on the layout. For example, if you set the height and position attributes of a div object, the content of the div object determines its width ).
This attribute is read-only for currentStyle objects. Other objects can be read and written.
The corresponding script feature is position.
Example: div {position: relative; top:-3px}
How can we understand absolute and relative positioning in CSS styles?
Absolute and relative positioning depends on the situation ..
The text div and parent div can be located using margin.
A very important attribute of div is float .. The floating property of the div.
The div layer often runs in disorder. All people think it is better to use relative positioning when setting the div position ..
For example, the sub-div should be positioned with the parent div as the reference object.