位置:relative;
元素相对于其正常位置进行定位。position: relative
;
设置相对位置元素的 top、right、bottom 和 left 属性将导致 它要调整到远离其正常位置的位置。其他内容不会进行调整以适应 元素。
div.relative {
position: relative;
left: 30px;
border: 3px solid #73AD21;
}
![](https://img.haomeiwen.com/i21922576/c8839aaa703dae36.png)
位置:fixed;
元素相对于视口定位,这意味着它始终 即使页面滚动,也会保持在同一位置。top, right、bottom 和 left 属性用于定位元素。position: fixed
;
固定元素不会在页面中留下它通常所在的空白。请注意页面右下角的固定元素。
div.fixed {
position: fixed;
bottom: 0;
right: 0;
width: 300px;
border: 3px solid #73AD21;
}
![](https://img.haomeiwen.com/i21922576/1063376f60ecd026.png)
网友评论