2个div,灵活的高度,没有滚动条

时间:2013-07-08 16:41:26

标签: css html scrollbar extend

我一直在努力让我的网站有2个div,它们延伸到页面底部(到页脚)而没有滚动条。例如:http://hoskyns50.co.uk/about-hoskyns-50th/我想删除滚动条并使div扩展页面(就像这个网站一样),内容的白色背景和侧边栏div在页面下方可见到页脚。< / p>

相关的css:

body, html {
    position: absolute;
    left: 0px;
    right: 0px;
    bottom: 0px;
    top: 0px;
    min-height: 100%;
    height: 100%;
    line-height: 1;
    }
body { 
    min-height: 100%;
    height: 100%;
    font-family: 'Century Gothic', sans-serif;
    font-size: 13px;
    line-height: 21px;
    background: #e0d6b6 url(images/bg.png) repeat-x;
    color: #2f2f2f;
    -webkit-font-smoothing: antialiased;
    -webkit-text-size-adjust: 100%; 
    }
.container {
    position: absolute;
    left: 0px;
    right: 0px;
    bottom: 0px;
    top: 0px;
    width: 100%;
    min-height: 100%;
    height: auto !important;
    height: 100%;
    background: transparent;
    margin: 0 auto -30px;
    padding: 0px;
    }
.contentwrapper {
    position: relative;
    display: block;
    min-height: 100%;
    height: 100%;
    margin: 0 5%;
    }
#content, #sidebar {
    position: relative;
    padding: 20px;
    background: #ffffff;
    min-height: 100% !important;
    height: 100%;
    display: block;
    position: relative;
    overflow: auto;
    margin-bottom: auto;
    }
#content {
    min-width: auto;
    width: auto;
    }
#sidebar {
    margin-left: 2% !important;
    width: 150px;
    float: right;
    }#footer, #push {
    clear: both;
    }
#footer {
    display: block;
    bottom: 0px !important;
    position: relative;
    width: 100%;
    margin: 0;
    padding: 10px 0;
    font-size: 12px;    
    border: none;
    background: #808080;
    color: #c4c4c4;
    vertical-align: middle;
    }

相关的html

<html>
<head>
</head>
<body>
<div class="container">
<div class="contentwrapper">
<div id="sidebar">
sidebar
</div><!--sidebar-->
<div id="content">    
content
</div><!--content-->
</div><!--contentwrapper-->
<div id="push"></div>
<div id="footer">
footer
</div> <!--footer-->
</div><!--container-->
</body>
</html>

2 个答案:

答案 0 :(得分:0)

在CSS顶部使用此CSS重置:

html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td,article,aside,canvas,details,embed,figure,figcaption,footer,header,hgroup,menu,nav,output,ruby,section,summary,time,mark,audio,video{margin:0;padding:0;border:0;font-size:100%;font:inherit;vertical-align:baseline}article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section{display:block}body{line-height:1}ol,ul{list-style:none}blockquote,q{quotes:none}blockquote:before,blockquote:after,q:before,q:after{content:'';content:none}table{border-collapse:collapse;border-spacing:0}

这应该是正确的:

body { 
    min-height: 100%;
    font-family: 'Century Gothic', sans-serif;
    font-size: 13px;
    line-height: 21px;
    background: #e0d6b6 url(images/bg.png) repeat-x;
    color: #2f2f2f;
    -webkit-font-smoothing: antialiased;
    -webkit-text-size-adjust: 100%; 
}
body, html {height: 100%; }
.container {
    position: absolute;
    left: 0px;
    right: 0px;
    bottom: 0px;
    top: 0px;
    width: 100%;
    min-height: 100%;
    height: auto !important;
    height: 100%;
    background: transparent;
    margin: 0 auto -30px;
    padding: 0px;
    }
.contentwrapper {
    position: relative;
    display: block;
    min-height: 100%;
    height: 100%;
    margin: 0 5%;
    }
#content, #sidebar {
    position: relative;
    padding: 20px;
    background: #ffffff;
    min-height: 100% !important;
    height: 100%;
    display: block;
    position: relative;
    overflow: auto;
    margin-bottom: auto;
    }
#content {
    min-width: auto;
    width: auto;
    }
#sidebar {
    margin-left: 2% !important;
    width: 150px;
    float: right;
    }#footer, #push {
    clear: both;
    }
#footer {
    display: block;
    bottom: 0px !important;
    position: relative;
    width: 100%;
    margin: 0;
    padding: 10px 0;
    font-size: 12px;    
    border: none;
    background: #808080;
    color: #c4c4c4;
    vertical-align: middle;
}

答案 1 :(得分:0)

在你的CSS中更改:

#content, #sidebar {
    position: relative;
    padding: 20px;
    background: #ffffff;
    min-height: 100% !important;
    height: 100%;
    display: block;
    position: relative;
    overflow: auto;
    margin-bottom: auto;
    }

为:

#content, #sidebar {
    position: relative;
    padding: 20px;
    background: #ffffff;
    min-height: 100% !important;
    height: 100%;
    display: block;
    position: relative;
    overflow: hidden;
    margin-bottom: auto;
    }

请注意,只更改了overflow值。