[英]footer at bottom text in middle
I'm trying to keeping footer at bottom no matter how much text there is in the content. 无论内容中有多少文本,我都试图将页脚放在底部。 What am i doing wrong?
我究竟做错了什么? The layout is:
布局为:
.top{
width:500px;
height:100px;
background-color:black;
}
.content{
width:500px;
min-height:100%;
position:relative;
}
.footer{
width:500px;
height:100px;
background-color:blue;
position:absolute;
bottom:0;
}
<div class="top"></div>
<div class="content"></div>
<div class="footer"></div>
http://jsfiddle.net/RDuWn/68/ http://jsfiddle.net/RDuWn/68/
Regards, Simon 问候西蒙
Your code works but you need to set min-height instead of height in your footer class so that it can stretch to your content size. 您的代码可以工作,但是您需要在页脚类中设置最小高度而不是高度,以便可以扩展到您的内容大小。
.footer{
width:500px;
min-height:100px;
background-color:blue;
position:fixed;
bottom:-1px;
}
Here's how it will look with that change, and some placeholder content added to the footer. 更改后的外观如下 ,并将一些占位符内容添加到页脚中。
It was your absolute positioning that caused the overlap. 导致重叠的是您的绝对位置。 An absolute element is removed from the normal flow and becomes "ignored", per se, by the other elements when determining position.
在确定位置时,绝对元素会从正常流程中删除,并被其他元素“忽略”。 If you don't specify a position in the css, it defaults to static positioning and all elements will properly be in the "flow".
如果您未在CSS中指定位置,则默认为静态定位,并且所有元素都将正确地位于“流”中。
http://www.w3schools.com/css/css_positioning.asp http://www.w3schools.com/css/css_positioning.asp
Here's the CSS I used: 这是我使用的CSS:
.top{
width:500px;
height:100px;
background-color:pink;
}
.content{
width:500px;
min-height:100%;
background-color:blue;
}
.footer{
width:500px;
height:100px;
background-color:black;
margin-bottom:0px;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.