【问题标题】:Fill in sidebar downwards向下填充侧边栏
【发布时间】:2012-05-19 16:32:32
【问题描述】:

我正在练习如何创建模板。我的第一个问题是如果内容的长度不足以填满整个屏幕,如何将页脚粘贴在屏幕底部。使用本教程解决了它http://matthewjamestaylor.com/blog/keeping-footers-at-the-bottom-of-the-page

我的另一个问题是如何将侧边栏一直填充到页脚。

这是html:

<div id="wrapper">
    <div id="header">
        header here
    </div>
    <div id="container">
        <div id="sidebar">
            sidebar here
        </div>
        <div id="content">
            content here
        </div>
    </div>
    <div class="cls"></div>
    <div id="footer">
        footer here
    </div>
</div>

这是css:

body{
    padding: 0;
    margin: 0;
}
.cls{
    clear:both;
}
#wrapper{
    min-height: 100%;
    position: relative;
}
#header{
    background-color: #DDDDDD;
    height: 60px;
}
#container{
    padding-bottom: 60px;
    width: 100%;
}
#sidebar{
    background-color: #87CEFA;
    width: 220px;
    float: left;
    padding-right: 20px;
}
#content{
    width: 75%;
    float:right;
}
#footer{
    background-color: #CCCCCC;
    bottom: 0;
    position: absolute;
    width: 100%;
    height: 60px;
}

打开图片链接,左边的就是我现在拥有的......我希望结果是右边的 http://www.4shared.com/photo/CoXrUWP2/template.html

【问题讨论】:

标签: html css


【解决方案1】:
#sidebar{
    background-color: #87CEFA;
    width: 220px;

    min-height:600px;
    height:auto !important;
    height:600px;   

    float: left;
    padding-right: 20px;
}

试试这个,看看它是否适合你?

【讨论】:

    【解决方案2】:

    实现这一目标的主要方法有三种。

    其中一个是使用表格布局,我会提防。

    第二个是在#container 元素上设置背景。 在 Photoshop 中,使用 220 像素的侧边栏创建一个图像,并使用其中的一部分使侧边栏的外观延伸到 #container 元素的整个高度。

    第三个是使用 JQuery 将#sidebar 元素调整为容器的高度,这样就可以了:

    $("#sidebar").height( $("#container").height() );
    

    【讨论】: