html - Bootstrap 侧导航栏固定

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

我有这段代码,并希望它即使在向下滚动时也始终可见:

 .sidenav {
            padding-top: 20px;
            background-color: #f1f1f1;
            height: 100%;
        }

        @media screen and (max-width: 767px) {
            .sidenav {
                height: auto;
                padding: 15px;
            }
            .row.content {height:auto;} 
        }
        /* Remove the navbar's default margin-bottom and rounded borders */ 
        .navbar {
            margin-bottom: 0;
            border-radius: 0;
        }

        /* Set height of the grid so .sidenav can be 100% (adjust as needed) */
        .row.content {height: 450px}

        body { padding-top: 45px; }

<div class="container-fluid text-center">    
        <div class="row content">
            <div class="col-sm-2 sidenav">
                <p><a href="#">Link</a></p>
                <p><a href="#">Link</a></p>
                <p><a href="#">Link</a></p>
            </div>

https://jsfiddle.net/kuukdn9u/

有什么建议吗?

最佳答案

如果您希望两侧栏都可见:

  • 将名为 sidenav-leftsidenav-right 的广告 ID 分别应用于左侧和右侧的侧边栏。这将允许这两个元素受到新样式的影响。
  • 使用 fixed 定位这些元素
  • 将包含文本的div推离左侧边栏中间或远离左侧边栏,以防止在左侧边栏应用position fixed时重叠

    您可以使用下面的这些规则

    .text-center {
      left: 150px;
    }
    
    #sidenav-left {
      position: fixed;
      width: 150px;
      left: 0
    }
    
    #sidenav-right {
      position: fixed;
      right: 0;
    }
    

    see codepen here

  • 关于html - Bootstrap 侧导航栏固定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43028264/

    相关文章:

    html - bootstrap 中的语言符号

    jquery - 如何更改点击时的模式内容(Bootstrap)

    javascript - 当元素在 AngularJS 中可见时运行一些 DOM 操作

    javascript - html表格单元格以更好的方式显示在输入框中输入的文本

    jquery - 重新加载 CSS 仅适用于鼠标悬停在窗口上

    javascript - 悬停在链接上时的新图像

    html - 是否可以使用 Rvest 抓取 html 节点中不包括子类的数据?

    html - Bootstrap 网格列对齐问题

    html - 当居中元素的高度大于窗口高度时如何禁用垂直居中? (没有Javascript)

    javascript - 使 Canvas 的clearRect()工作得更快