【发布时间】:2013-03-30 20:39:23
【问题描述】:
我希望在我的网站上滚动时修复标题和导航栏。我可以将这两个都修复,但是#container div 中的内容不会出现在它们下面。
我目前使用以下方法使我的网站内容显示在标题下方,但不确定如何计算 #header 和 #navbar id 的 margintop。
#header{
width:100%;
position:fixed;
top:0px;
}
#navbar{
width:100%;
height:50px;
margin:auto;
position:fixed;
top:120px;
}
$(document).ready(function () {
$('#container').css('marginTop', $('#header').outerHeight(true) );
});
感谢您的帮助。
【问题讨论】:
-
你能设置一个jsfiddle吗?
-
设法弄明白了: $(document).ready(function () { $('#container').css('marginTop', $('#header').outerHeight(true ) + $('#navbar').outerHeight(true) ); });
标签: javascript jquery css