我固定了侧边栏和导航栏,我想知道是否可以根据每篇文章的宽度调整侧边栏的 x 位置。
HTML:
<div id="sidebar">
</div>
CSS:
div#sidebar{
width: 200px;
height: 100%;
position: fixed;
margin-top: 50px;
float: left;
}
最佳答案
在文章中设置侧边栏怎么样?
HTML:
<div id="article">article
<div id="sidebar">sidevar
</div>
</div>
CSS:
#article
{
margin-left: 30px;
background: white;
width: 200px;
height: 300px;
}
#sidebar
{
position: fixed;
top: 0px;
width: 30px;
height: 100%;
background: blue;
color: white;
}
关于html - 固定 div 在 y 位置但不在 x 位置取决于其他 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27728347/