html - 窗口缩小时 Bootstrap 列重叠

标签 html css twitter-bootstrap-3

我看了看其他帖子,似乎找不到这个问题的答案。

我正在尝试使用 Bootstrap 制作网页。我想要一个固定在左侧的垂直 nabvar,占据 3 列,右侧的内容占据 9 列。我已经实现了 scrollspy 来在滚动时更新导航栏。

在我缩小屏幕之前,它工作得很好。我的理解是它应该将列放在彼此之上。如果我从列中删除词缀属性,它会正确更新,但导航栏未固定,因此 scrollspy 毫无意义。

这是我的代码:

ul.nav-pills {
  padding-top: 20px;
  top: 20px;
}

.item {
  padding-top: 70px;
}

#content {
  margin-bottom: 600px;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <title>Meet Sarah</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="css/sarah.css">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

</head>

<body data-spy="scroll" data-target="#myScrollspy" data-offset="20">

  <div class="container-fluid">
    <div id="content" class="row">
      <nav class="col-sm-3" id="myScrollspy">
        <ul class="nav  nav-pills nav-stacked  " data-spy="affix">
          <li class="active snav-item">
            <a class="nav-link" href="index.html">Home</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="#about_me">About Me</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="#school">Colorado School of Mines</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="#alpine">Alpine Ski Racing</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="#music">Music</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="#outreach">Outreach</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="#extra">Extracurriculars</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="#likes">Obsessions</a>
          </li>
        </ul>
      </nav>

      <div class="col-sm-9">
        <div id="about_me" class="container-fluid item">
          <h1>About Me</h1>
          <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
          <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
        </div>

        <div id="school" class="container-fluid item">
          <h1>Colorado School of Mines</h1>
          <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
          <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
        </div>

        <div id="alpine" class="container-fluid item">
          <h1>Alpine Ski Racing</h1>
          <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
          <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
        </div>

        <div id="music" class="container-fluid item">
          <h1>Music</h1>
          <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
          <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
        </div>

        <div id="outreach" class="container-fluid item">
          <h1>Outreach</h1>
          <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
          <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
          <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
        </div>

        <div id="extra" class="container-fluid item">
          <h1>Extracurriculars</h1>
          <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
          <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
        </div>

        <div id="likes" class="container-fluid item">
          <h1>Obsessions</h1>
          <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
          <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
        </div>


      </div>
    </div>
  </div>

</body>

</html>

关于如何修复我的左侧导航栏而不使其在较小的屏幕上重叠有什么建议吗?

最佳答案

尝试将“col-sm-9”更改为“col-md-9”或“col-lg-9”。哪个效果更好。或者使用“col-9”。

  ...
  <div class="col-9">
    <div id="about_me" class="container-fluid item">
      <h1>About Me</h1>
      <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
      <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
    </div>
    ...

关于html - 窗口缩小时 Bootstrap 列重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48846536/

相关文章:

html - Twitter Bootstrap 创建一个普通的页脚

jquery - 新页面打开后,事件类未保留在 mvc3 Bootstrap 导航栏中的选定列表项上

html - 谷歌浏览器 - 字段集溢出错误

html - 内联 li 文本相对于背景图像的垂直定位

javascript - 使元素引用不那么笨重

javascript - Selenium - 无法找到隐藏的元素

javascript - 让某些 td 交换位置

twitter-bootstrap - 在 Bootstrap 中关闭模式后如何取消模式触发按钮的焦点

html - 如何在调整可调整大小的 div 时获取 ScaleX 和 ScaleY 值..?

html - 使用 css 表格排列 div