position: absolute;
时间: 2023-09-13 07:04:13 浏览: 84
The CSS property "position: absolute;" is used to position an element relative to its nearest positioned ancestor or the initial containing block if there is no positioned ancestor. This means that the element will be taken out of the normal document flow and positioned at a specific location on the page, regardless of other elements around it.
Once an element is positioned absolutely, its position can be defined using the "top", "right", "bottom", and "left" properties. These properties specify the distance between the element's edges and the corresponding edges of its containing block.
Here is an example of how to use "position: absolute;" in CSS:
```
.container {
position: relative;
}
.box {
position: absolute;
top: 50px;
left: 100px;
}
```
In this example, the "container" element has a positioning context set to "relative". This means that any absolutely positioned child elements will be positioned relative to the "container". The "box" element is then positioned absolutely, with a distance of 50px from the top and 100px from the left of its containing block.
阅读全文