【问题标题】:Content under fixed header and navbar when scrolling滚动时固定标题和导航栏下的内容
【发布时间】: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


【解决方案1】:
 $(document).ready(function () { $('#container').css('marginTop', $('#header').outerHeight(true) + $('#navbar').outerHeight(true) ); }); 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-12
    • 2019-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-07
    相关资源
    最近更新 更多