繁体   English   中英

修复了导航栏在Bootstrap中隐藏内容的问题

[英]Fixed nav-bar hides content in Bootstrap

我有固定的导航栏,该导航栏在使用选项卡时隐藏内容。 当我不在选项卡之间导航时,导航栏会正确显示,当我单击一个选项卡时,导航栏会隐藏包括选项卡标题的内容。

在此处输入图片说明

单击选项卡之一后,内容将被隐藏。 在此处输入图片说明

我尝试使用此方法,但仅在不在选项卡之间导航时才有效。

body{
margin-top: 80px;
}

伙计们,这是我在jsfiddle上的示例 ,我认为这可能是我的javascript,当我不使用hash它工作正常。 用户刷新页面时需要hash ,最后一个打开的选项卡需要处于活动状态。

 $('#sign-up-tabs a').click(function (e) {
    e.preventDefault();
    $(this).tab('show');
});

// store the currently selected tab in the hash value
$("ul.nav-tabs > li > a").on("shown.bs.tab", function (e) {
    var id = $(e.target).attr("href").substr(1);
    window.location.hash = id;
});

// on load of the page: switch to the currently selected tab
var hash = window.location.hash;
$('#sign-up-tabs a[href="' + hash + '"]').tab('show');

已解决:我已通过将代码更改为以下内容来解决了该问题。

$('#sign-up-tabs').on('click', 'a', function (e) {
  e.preventDefault();
  // add this line
   window.location.hash = $(this).attr('href');
  $(this).tab('show');
 });
// on load of the page: switch to the currently selected tab
  var hash = window.location.hash;
 $('#sign-up-tabs a[href="' + hash + '"]').tab('show');

在jsfiddle上

您必须将navbars容器更改为使用display: block

如果它还没有放在容器中,则应将其放在div中,它可能会像魅力一样工作。

例如,如果您正在使用:

<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
  <div class="navbar-header">
    <!-- the rest of your code -->
  </div>
</nav>

您应该将其更改为:

<div style="height: 80px">
  <nav class="navbar navbar-default navbar-fixed-top" role="navigation">
    <div class="navbar-header">
      <!-- the rest of your code -->
    </div>
  </nav>
</div>

根据导航栏的高度在容器上添加顶部填充。 例如,如果导航栏高度为90px,则必须给容器顶部填充90px。

.container {
    padding-top:170px;
} 

暂无
暂无

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

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