我创建了两个div,一个在顶部,一个在底部。 我创建了一个按钮。我在左下角页面给了一个固定位置的财产。 如果我滚动页面,按钮仅固定在该位置。 基本上按钮处于整个页面的固定位置。 我的要求: 当我滚动页面时,按钮应该只固定一定的高度。 当我滚动页面时,按钮应该只固定在左边按钮,直到第一个div底线触及按钮底线。 和文我滚动页面的按钮应该与第一个div的底线一起移动。只有一个div的固定位置的按钮
基本上按钮应该是固定的位置,直到第一个div底线。 当第一个div底线与按钮底线一起折叠时,该按钮应该是相对/绝对的并随之一起移动。
希望你明白我的要求。 下面是我的代码,我找的要求
#top {
border: 1px solid black;
height: 900px;
width: 80%;
position: absolute;
}
.button {
background-color: #4CAF50;
border: none;
color: white;
bottom: 0px;
font-size: 16px;
margin-left: 0px;
cursor: pointer;
padding: 10px 24px;
position: fixed;
}
#bottom {
border: 1px solid black;
height: 900px;
width: 80%;
top: 910px;
position: relative;
}
#middle {
bottom: 50px;
position: fixed;
}
<html>
<body>
<div id="top">
<div id="middle">
<button class="button">Fixed Element</button>
</div>
</div>
<br>
<br>
<div id="bottom">
</div>
</body>
</html>
位置固定是相对于视,有这个quesiton一些有用的提示:HTTP: //stackoverflow.com/questions/5209814/can-i-position-an-element-fixed-relative-to-par你可能会觉得有用。 – connorb