html - 如何获得页眉固定顶部、容器可滚动和页脚固定底部的侧边栏?

标签 html css twitter-bootstrap sidebar

我正在尝试制作侧边栏,这正是我所期待的: enter image description here

  • Header fixed topFooter fixed bottom(我不知道“固定”是否正确,但我希望它们不要与边栏容器重叠)
  • 可滚动的侧边栏容器

我尝试调整 div 的位置,但没有成功。 我还尝试了粘性页脚的方法,但效果不佳。 我试着用谷歌搜索我的问题,但大多数答案都是网站的整个布局。 我需要它在我的侧边栏中工作。

这是我的:jsFiddle

代码有点长,所以我只贴出 CSS:

        html, body {
            height: 100%;           
        }


        #wrap {
            min-height: 100%;
            height: auto !important;
            height: 100%;            
            margin: 0 auto -60px;
        }

        #push, #footer {
            height: 60px;
        }

        .container-fluid {    
            width: 100%;
            height: 100%;
        }

        #content {
            position: absolute;
            width: 100%;
            bottom: 60px;
            top: 42px;
            right: 0px;
            left: 0px;
            padding: 0px;
        }

        #sidebar {    
            position:absolute;
            width:300px;
            height:100%;                    
        }

        #sidebar .ul-menu {
            margin:0px;
        }

        #sidenavbar .tabs-left>.nav-tabs>li>a{    
            margin: 0px;
            min-width: 30px;
            width: 70px;
            -webkit-border-radius: 0px 0 0 0px;
            -moz-border-radius: 0px 0 0 0px;
            border-radius: 0px 0 0 0px;
            border: 0px;
        }

        .sidebar-tab-content {
            background: #FFF;
            position: absolute;
            height: 100%;
            left: 94px;
            width:100%;
        }

        #sidenavbar .tabs-left>.nav-tabs {
            border: 0px;
        }      

        #footer {
            color: #FFF;
            background-color: #666;
        }

    .side-header, .side-footer {
        background: #AAF;    
    }
    h2 {
        margin: 0px;
   }

最佳答案

谢谢你的想法。我刚刚通过添加这些 css 代码 解决了我的问题:

       .side-header {
            position: absolute;
            top: 0px;
            right: 0px;
            left: 0px;
        }
        .side-container {
            position: absolute;
            bottom: 40px;
            top: 40px;
            overflow-y: auto;
        }

        .side-footer {
            position: absolute;
            bottom: 0px;
            left: 0px;
            right: 0px;
        }

这是 JSFiddle:http://jsfiddle.net/geddemet/XCn7C/

这个社区真的很有帮助。干杯!

关于html - 如何获得页眉固定顶部、容器可滚动和页脚固定底部的侧边栏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17877540/

相关文章:

HTML 将主要元素分配给一个 id

html - 页眉和页脚不随正文滚动

javascript - 根据选择的选择显示 3 个 div 之一

html - 垂直和水平居中时出现滚动条,无法摆脱

html - bootstrap 4 中的自定义卡片组

html - 使用 html、CSS 自动弹出关闭按钮

PHP 在 Iframe 之外重定向

html - 缩小浏览器窗口 - 按钮图标不会出现在它们应该出现的位置

javascript - .htaccess文件不加载js和css

html - 删除我的 html Bootstrap 网页中无法理解的空格