I am making a small div on the center of the page which has a footer which is fixed but the div is scroll-able.
According to me there are two ways to do it:
- Using
position:fixed
: Fixed position actually work relative to the browser window but I want position relative to my small div - Using
position:absolute
: Usingbottom:0;
I solved the problem initially but the footer scroll with the div text.
<% 1 > HTML % 1 > :
<div id="wrapper">
<div id="box">
<div id="header">
<h1>Heading</h1>
</div>
<div id="content">
Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text
</div>
<div id="footer">
<p>Fooooooooooooooooooooooooooter</p>
</div>
</div>
</div>
<强度 > CSS 强度 > :
#wrapper{
width:600px;
height:500px;
border:thin solid #c00;
}
#box {
width:400px;
height:300px;
margin:100px auto;
border:medium dashed #c00;
position:relative;
overflow:auto;
}
#content {
background-color:rgba(0,0,208,0.1);
}
#footer {
position:absolute;
bottom:0px;
width:100%;
height:50px;
background-color:rgba(0,0,0,0.8);
color:#fff;
}
见:"http://jsfiddle.net/knoxxs/6W5uq/19" rel="noreferrer" >JSdidle
如何使页脚固定这个div?