向下填写侧边栏

时间:2012-05-11 03:56:21

标签: html css

我正在练习如何创建模板。我的第一个问题是如果内容不够长以填满整个屏幕,如何将页脚粘贴在屏幕底部。它是使用本教程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

2 个答案:

答案 0 :(得分:0)

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

一个是使用表格布局,我会提醒你。

第二个是在#container元素上设置背景。 在photoshop中,使用220px侧边栏创建一个图像,然后使用它的一部分使侧边栏的外观扩展到#container元素的整个高度。

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

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

答案 1 :(得分:0)

#sidebar{
    background-color: #87CEFA;
    width: 220px;

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

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

试一下,告诉它是否适合您?