I am making a small div in the center of the page that has a footer that is fixed, but the div has the ability to scroll.
In my opinion, there are two ways to do this:
- Using
position:fixed
: a fixed position actually works relative to the browser window, but I want a position relative to my small div - Using
position:absolute
: Using bottom:0;
I solved the problem first, but the footer scrolls with the text div.
HTML
<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>โ
<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; }โ
To watch: JSfiddle
How to make the footer fixed for this div?
source share