这里是我的主页的简化版本:一个固定的div,保持其父宽度?
<div class="main">
<div class="content"> all the content of my website </div>
<div class="nav"> fixed on the screen and always visible </div>
</div>
而这里的相应的CSS:
.main {
max-width: 500px;
height: 2000px;
margin: auto;
background-color: grey;
}
.nav {
width: 100px;
height: 100px;
background-color: blue;
position:fixed;
right: 0; /* that's the issue */
}
我想作为固定要素留在它的父(触摸其父的右边缘)。但现在它正在触摸屏幕的右边界。
任何想法如何解决这个问题?谢谢!
只需使用一个浮动的权利,而不是一个位置的? –
但我确实希望div是固定的,所以即使在滚动时它也始终显示在屏幕上。 – Thomas
你将需要使用一点的JavaScript这个和绝对定位 – Pete