CSS 中的 position 属性值
position 属性用于指定元素在父元素或页面中的定位方式。它有以下可能的值:
1. static (默认值)
- 元素位于文档流的正常位置。
2. relative
- 元素相对其原始位置移动,而不会影响其他元素的位置。
3. absolute
- 元素从文档流中移除,并根据其父元素或
元素(如果未指定父元素)定位。
4. fixed
- 元素与视口固定,滚动页面时保持在同一位置。
5. sticky
- 元素在达到指定阈值后固定在视口或容器中。
使用示例:
<code class="<a style=\'color:#f60; text-decoration:underline;\' href=" https: target="_blank">css">/* 将元素向右移动 50px */ .element { position: relative; left: 50px; } /* 将元素从页面顶部 100px 处开始定位 */ .element { position: absolute; top: 100px; } /* 将元素固定在视口右侧 */ .element { position: fixed; right: 0; }</code>