Reprinted: <a href = "http://www.happyshow.org/article/125.html" target = "_ blank">Position has three values: static (static), relative (relative), and absolute (absolute). Because static is the default value of all page elements, therefore, this value is hardly required when you set the element positioning type unless it is used to overwrite the previous definition. For the latter two, it is generally used to place an absolute positioning element in a relative positioning element,
Child Element B can be precisely located through top, right, bottom, and left. The target of positioning is parent element A with relative positioning attributes. After these offsets are set, the resulting gaps are filled by the following elements (if the following elements are of sufficient size ). Element B has the absolute positioning attribute, which is equivalent to extracting from the document stream and floating in the original layout to form a "layer". If there are multiple "layers ", there must be who will cover and who will compete with each other. To solve this competition, the z-index (z-axis of the spatial Coordinate System) attribute will be generated, if the value is big, then everyone will be there. In addition, if element A of the parent level does not set relative, Element B uses the body tag as the reference point.For element A with the position: relative attribute, its top, right, bottom, and left offsets take the original position of the element as the reference point, rather than as mentioned above, take the parent element or body with the relative positioning attribute as the reference point. A gap is generated after an offset is set, and the elements around the gap are not filled, even if they are adequate (for demonstration ). It is worth noting that, at this time, the margin and margin of element A will act on the original position of the element, because the original position produces an offset, the final position of the element will be the position after the combination of margin and top, right, bottom and left, and the position of the surrounding elements will also be affected. Let's look at the absolute in relative, such as the and B elements above. If both elements have top, right, bottom, and left, for Element B, the reference point of its location offset is the position after the offset of Element A, not the original position of Element A. Similarly, if Element B has margin, its reference point is also the position after the offset of Element, this is very important. This is the concept of absolute (demonstration ). |