简体   繁体   English

滚动时固定标题和导航栏下的内容

[英]Content under fixed header and navbar when scrolling

I want the header and navbar to be fixed when scrolling on my site. 我想在网站上滚动时固定标题和导航栏。 I can make these both fixed, however the content in the #container div doesn't appear under them. 我可以将它们固定下来,但是#container div中的内容不会出现在它们下面。

I currently use the following to make the content of my site appear below the header but not sure how to calculate the margintop for the #header AND #navbar ids. 我目前使用以下内容使网站内容显示在标题下方,但不确定如何计算#header和#navbar ID的边距。

#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) );

                });

Thanks for your help. 谢谢你的帮助。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM