2013-03-30 88 views
0

我想在我的网站上滚动时修正标题和导航栏。我可以使这两个都是固定的,但是#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)); 

       }); 

感谢您的帮助。

+1

你可以设置一个jsfiddle。 – btevfik

+0

设法弄明白了: $(document).ready(function(){('#container')。css('marginTop',$('#header')。outerHeight(true)+ $( '#navbar')。outerHeight(true)); }); – user1060187

回答

0
$(document).ready(function() { $('#container').css('marginTop', $('#header').outerHeight(true) + $('#navbar').outerHeight(true)); });