The absolute positioning reference method is positioned relative to its nearest positioned ancestor element. If there is no positioned ancestor element, it is positioned relative to the original containing block. The reference method has the following aspects: 1. The positioning method of ancestor elements. If you want to use absolute positioning, you first need to find an ancestor element closest to the target element; 2. The concept of containing blocks. If there is no positioned ancestor element, absolute positioning The positioned element will be positioned relative to the original containing block; 3. Positioning attribute, specifying the position of the absolutely positioned element in the reference element; 4. Stacking order, etc.
# Operating system for this tutorial: Windows 10 system, Dell G3 computer.
Absolute positioning is a commonly used positioning method in CSS, which can accurately place elements at specified locations on the web page. The reference method of absolute positioning is to position relative to its nearest positioned ancestor element, or, if there is no positioned ancestor element, relative to the original containing block (usually the body element).
The reference method of absolute positioning can be understood from the following aspects:
Positioning method of ancestor elements:
Absolutely positioned elements are relative Positioned relative to its nearest positioned ancestor element. The so-called positioned ancestor element refers to the element whose position attribute value is relative, absolute, fixed or sticky. If you want to use absolute positioning, you first need to find the nearest ancestor element to the target element.
Concept of containing block:
If there is no positioned ancestor element, an absolutely positioned element will be positioned relative to the original containing block. The containing block refers to the area where the element is ultimately rendered, usually the body element. In some special cases, the containing block can also be other elements, such as elements whose position attribute value is set to relative, absolute, fixed, or sticky.
Positioning attributes:
Absolutely positioned elements can specify their position in the reference element through the top, right, bottom and left attributes. The value of these properties can be pixels, percentage, or auto. The top attribute specifies the distance between the top edge of the element and the top edge of the reference element, the right attribute specifies the distance between the right edge of the element and the right edge of the reference element, the bottom attribute specifies the distance between the bottom edge of the element and the bottom edge of the reference element, and the left attribute Specifies the distance between the left edge of the element and the left edge of the reference element.
Stacking order:
Absolutely positioned elements can control their hierarchical relationship in the stacking context through the z-index attribute. The larger the value of the z-index attribute, the higher the element is in the stacking context and the easier it is to cover other elements.
To summarize, the reference method of absolute positioning is to position relative to its nearest positioned ancestor element. If there is no positioned ancestor element, position it relative to the original containing block. The position of the element within the reference element can be specified through the top, right, bottom and left attributes. In a stacking context, the hierarchical relationship of absolutely positioned elements can be controlled through the z-index attribute.
The above is the detailed content of What method does absolute positioning refer to?. For more information, please follow other related articles on the PHP Chinese website!