【问题标题】:css right sidebar height 100%css右侧边栏高度100%
【发布时间】:2012-07-20 11:24:10
【问题描述】:

我发现很少有关于 100% 高度和粘性页脚的教程。 但是,我无法实现 100% 高度的右侧边栏。 我的侧边栏的高度似乎与侧边栏中的内容相关,即使它设置为 100%。 有什么想法吗?

这是我的html

    <body>
    <div id="container">
<div id="header">
</div>
   <div id="wrap">
        <div id="sidebar-right">
            <div id="menu">
                  lorem ipsum
              </div>
        </div>
        <div id="content">
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus adipiscing, nunc quis vehicula vehicula, mi nunc tempor lorem, nec congue augue neque vitae augue. 
   </div>
<div class="push"></div>
</div>
<div class="footer">
</div>
</body>

还有 CSS

html, body{margin: 0; padding: 0; height: 100%;}
#sidebar-right{
    background: #ccc;
    float: right;
    height: 100%;
    width: 300px;
    border-left: 2px #fff solid;
}
#container{
height: auto !important;
    margin: 0 auto -142px;
    min-height: 100%;
}

#wrap {
    height: 100%;
    overflow: hidden;
    }

#menu {margin: 150px 0 0 50px;} 

.footer {
    background: none repeat scroll 0 0 #BA6F19;
    clear: both;
    height: 100px;
    position: relative;
}   

#header {
    background: none repeat scroll 0 0 #BA6F19;
    height: 50px;
    padding: 20px;
}
#content {
    float: right;
    margin-top: 100px;
    width: 400px;
    height: 100%
    }
.footer, .push {
    height: 142px;
}   

【问题讨论】:

    标签: css height footer sidebar


    【解决方案1】:
    #sidebar-right{
        background: #ccc;
        float: right;
        height: 100% !important;
        width: 300px;
        border-left: 2px #fff solid;
    }
    

    试试这个?

    【讨论】:

    • 谢谢,但还没有解决问题。您可以在此处查看该网站:tndsigns.com/test/height
    • 我认为你可以将高度设为:400px。 (对不起,我的英语不好)
    • 这也行不通,因为它会使其固定高度。
    • 嗨,看看here 的可能方式,如何实现。您可以在#sidebar-right 中添加padding-bottom: 2000px; margin-bottom: -2000px; 并删除height:... 设置,并让#wrap { overflow:hidden} 保持现在的状态,然后右侧的列将按照您的预期进行拉伸。
    • 所以在我的情况下,我希望侧边栏一直向下(到页脚),而不管包装容器的高度如何。我还没有找到好的解决方案。还有其他想法吗?