2013-07-08 13 views
0

我一直在努力让我的网站有2个div,它们扩展到页面底部(到页脚),没有滚动条。例如:http://hoskyns50.co.uk/about-hoskyns-50th/我想删除滚动条并使div扩展页面(就像本网站所做的那样),内容和侧边栏div的白色背景可以从页面到页脚的整个路径显示。2灵活高度无滚动条div divs

相关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> 

回答

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; 
} 
+0

嗨,感谢您的回复。我编辑了我的CSS到上面,但我仍然看到内容div中的滚动条?任何其他想法? http://hoskyns50.co.uk/about-hoskyns-50th/ < - 自己看看 – user2561163

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值发生了变化。

+0

感谢您的回复,我已经尝试过,但是我希望我的访问者能够看到每个页面上的所有信息。将溢出变为隐藏意味着他们将无法在大页面上看到一半的信息......还有其他想法? – user2561163

+0

这是因为您将'height'设置为100%,在同一节中以及'.contentwrapper'中将其更改为'auto',您将看到不同之处。 – EmmanuelRC

+0

我也尝试过,但是当我将高度设置为自动时,div不会伸展到页面的底部。 – user2561163