Directory:1.static2.relative3.absolute4.fixed (Pending supplement)5. References 1.staticelements have the Position property, whose default value is "Static", which also means that they do not and do not accept the Location property setting (top, right, bottom, left property value settings). Another element sets the position property, which overrides the element's default value of "static". Static: Parent element-child element height relationshipin this example, the child element box-xx is set to height, and the parent element Box-set does not set the height. the height of the parent element is propped up by the child element height (primitive height)child element height:40px;child element height:80px; 2.relative"relative" can set offset (offset) top, right, bottom, and left properties for the element. These displacement property settings allow precise positioning of elements.
- Relative + Displacement Properties:
- still ∈ document flow;
- still occupies the original default location (the surrounding element can also see its default location);
- The displacement of the relative positioned element is relative to the edge of the element itself .
in fact, a relative positioning element sets both the "top" and "bottom" offset property values, in effect the top priority is higher than "bottom". However, a relative positioning element sets both "left" and "right" displacement properties, and their priority depends on which language the page is using, for example, if your page is an English page, then the "left" displacement property has a high priority, and if your page is Arabic, then "right" The displacement property has a high precedence. relative positioning elements: Parent element-child element height relationshipin this example, the child element box-xx is set to height, and the parent element Box-set does not set the height. the height of the parent element is propped up by the child element height (primitive height, independent of displacement) child element height:40px;child element height:80px; 3.absolute
- Absolutely positioned elements
- Out of document flow;
- At least one ancestor element is required to set relative positioning (absolute positioning), otherwise it will be positioned relative to the body of the page.
- Relative positioning of the ancestor ancestor + absolute positioning element Elem:
- If the Elem does not set the box displacement property, the top and left of the elem will be coincident with the top and left sides of the parent element with relative positioning set. (multiple elem will overlap)
- If Elem sets the box displacement property, Elem shifts the edge of the ancestor element that sets the offset position.
When an absolutely positioned element has a fixed height and width, and the box displacement sets both "top" and "bottom" at the same time, "top" has a higher priority group, and as with relative positioning elements, when both "left" and "right" are set, The priority depends on the language in which his page is used. absolute positioning element, parent element-child element Height relationship: parent element Relative, child element absolutein this example, the child element box-xx sets the height, and the parent element Box-set also sets the height. the height of the parent element is not propped up by a child element;But there is a connection: The child element is displaced relative to the edge of the parent elementparent element height:200px; child element height:80px;parent element height:200px; child element height:20px;parent element height:100px; child element height:80px;parent element height:10px; child element height:80px;parent element height:0; child element height:80px;
When an absolutely positioned element does not explicitly specify a height and width, while using the "top" and "bottom" properties of the box displacement, the entire element's height spans the entire container. Similarly, when this element uses both the offset "left" and "right" property values, the entire element's width spans the entire container. If you use the offset four property at the same time, you can specify a width and height display element. (This time the absolute positioning element width and height are all 100%.) )
box-1 does not specify height, width;top:10px; bottom:10px; /* Use top, bottom, height across the container * /left:10px; right:10px; /* Adapt left, right, width across the container * / 5. ReferencesHTML and CSS Advanced Guide II--positioning details
CSS Position notes + experiments