我有一个固定位置的标题(动态高度)。
我需要将容器 div 放在标题的正下方。由于页眉高度是动态的,我不能使用固定值作为上边距。
如何做到这一点?
这是我的 CSS:
#header-wrap {
position: fixed;
height: auto;
width: 100%;
z-index: 100
}
#container{
/*Need to write css to start this div below the fixed header without mentioning top margin/paading*/
}
...和 HTML:
<div id="header-wrap">
<div id="header">
<div id="menu">
<ul>
<li><a href="#" class="active">test 0</a></li>
<li><a href="#">Give Me <br />test</a></li>
<li><a href="#">My <br />test 2</a></li>
<li><a href="#">test 4</a></li>
</ul>
</div>
<div class="clear">
</div>
</div>
</div><!-- End of header -->
<div id="container">
</div>
最佳答案
您的#container 应该在#header-wrap 之外,然后为#header-wrap 指定一个固定高度,之后,为#container 指定margin-top 等于#header-wrap 的高度。像这样:
#header-wrap {
position: fixed;
height: 200px;
top: 0;
width: 100%;
z-index: 100;
}
#container{
margin-top: 200px;
}
希望这是您需要的: http://jsfiddle.net/KTgrS/
关于jquery - 在html中定位固定标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10975268/