css - Bootstrap : dropdown menu covers content

标签 css html twitter-bootstrap twitter-bootstrap-3

我的代码保存在 http://jsfiddle.net/qba2xgh6/1/ ,来自Bootstrap官网。

代码如下:

<div class="navbar navbar-default navbar-fixed-top" role="navigation">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-collapse">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>

      <a class="navbar-brand" href="index.php">My Brand</a>
    </div>
    <div class="collapse navbar-collapse navbar-right">
      <ul class="nav navbar-nav">
        <li><a href="index.php">Home</a></li>
        <li><a href="#contact">Contact</a></li>
      </ul>
    </div><!--/.nav-collapse -->
  </div>
</div>

<div class="container main">
  <p>
    Hello, the main content starts here.
    Hello, the main content starts here.
    Hello, the main content starts here.
    Hello, the main content starts here.
    Hello, the main content starts here.
    Hello, the main content starts here.Hello, the main content starts here.
  </p>
</div>

问题是当我点击右上角的下拉按钮时,下拉菜单出现并覆盖了主要内容。我怎样才能避免这种情况?我希望它能下推主要内容。

最佳答案

那是因为您正在使用使导航栏保持固定的 navbar-fixed-top 类——在文档流之外。您可以:

  • 删除该类。但它也会删除所有设备和分辨率上的行为。

  • 如果您想为所有人保留它但不为移动设备保留它,请添加此媒体查询:

    @media (max-width:768px) {
        .main {
            margin-top:0;
        }
        .navbar-fixed-top {
            position:static;
        }
    } 
    

检查这个 DemoFiddle

关于css - Bootstrap : dropdown menu covers content,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27191212/

相关文章:

javascript - Materialise 下拉菜单不起作用

Chrome 中的 CSS 下拉菜单问题

javascript - Bootstrap 模式根据 Chrome 中的背景高度多次打印同一页面

html - float 和固定宽度 li 的组合

html - 带有不透明度的包装器并在没有不透明度的情况下在此包装器上设置 div

html - 标题导航换行符

html - Web 应用布局指南

javascript - 如何使用 jQuery 将列表项添加到列表中?

javascript - 弹出窗口也会出现在页面加载时。我无法弄清楚错误

html - 选择带有 :nth-child 的嵌套元素