任何与职位相关的问题,然后查看此链接,您将获得快速解决方案。
http://learnlayout.com/position.html
固定的
固定元素相对于视口定位,这意味着即使页面滚动,它也始终保持在同一位置。与 relative 一样,使用 top、right、bottom 和 left 属性。
我相信您已经注意到页面右下角的固定元素。我现在允许你关注它。这是把它放在那里的CSS:
.fixed {
position: fixed;
bottom: 0;
right: 0;
width: 200px;
background-color: white;
}
相对的
除非您添加一些额外的属性,否则 relative 的行为与 static 相同。
.relative1 {
position: relative;
}
.relative2 {
position: relative;
top: -20px;
left: 20px;
background-color: white;
width: 500px;
}
绝对
absolute 是最棘手的位置值。absolute 的行为类似于 fixed,除了相对于最近的定位祖先而不是相对于视口。如果一个绝对定位元素没有定位的祖先,它使用文档正文,并且仍然随着页面滚动而移动。请记住,“定位”元素的位置是除了静态之外的任何东西。
这是一个简单的例子:
.relative {
position: relative;
width: 600px;
height: 400px;
}
.absolute {
position: absolute;
top: 120px;
right: 0;
width: 300px;
height: 200px;
}