Home  >  Article  >  Web Front-end  >  Detailed explanation of the differences and usage of the four values ​​​​of the Position attribute: static, fixed, relative, absolute

Detailed explanation of the differences and usage of the four values ​​​​of the Position attribute: static, fixed, relative, absolute

高洛峰
高洛峰Original
2017-03-16 09:52:412245browse

1, static (static positioning): Default value. Without positioning, the element appears in normal document flow (if top, bottom, left, right, z are set -indexThese attributes are not artificial).

2. Relative (relative positioning): Generate relatively positioned elements and position them relative to their original positions through the settings of top, bottom, left, and right. Hierarchical classification can be done through z-index.

3. Absolute (Absolute positioning): Generate an absolutely positioned element and position it relative to the first parent element that contains positioning (except static positioning). The position of the element is set using the "left", "top", "right" and "bottom" properties. Hierarchical grading can also be performed through z-index.

4. Fixed (fixed positioning): Generate absolutely positioned elements and position them relative to the browser window. The position of the element is set using the "left", "top", "right" and "bottom" properties. Hierarchical grading can also be performed through z-index.

z-index attribute sets the stacking order of elements. Elements with a higher stacking order will always appear in front of elements with a lower stacking order. That is, elements with large attribute values ​​are stacked on elements with small attribute values, but the prerequisite is that they are elements of the same level (Note: Z-index can only work on positioned elements, and elements can have negative z-index attributes. value.)


The above is the detailed content of Detailed explanation of the differences and usage of the four values ​​​​of the Position attribute: static, fixed, relative, absolute. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn