you got to have a lot of content that is first of all scrollable and then give your footer div the following properties:
CSS
position: fixed;
left: 0;
bottom: 0;
- One small note is that you got to have some content inside the footer HTML element in order for it to even render I provided the following text
A Footer!
(shown in the example below)
Other than giving a position: fixed
you need to guide the div where to be fixed it. Its default is to be fixed top left I believe. So to have it fixed to the bottom you can add left: 0
and bottom: 0
to have it behave as you desire.
Code Playground Example
I made a small example for you to check out that is working feel free to play around here It looks like this and as you can see the scroll handle is midway through the scroll track marked in red while the footer is fixed to the bottom as you wanted it to.
Demo
One Small Note
position: fixed
is what you desire. It will fix the divs position without being dependent on scroll event. position: sticky
is a sort of combination of position: relative
in default that in turn will shift to become position: fixed
when you scroll down enough and the div will then be fixed.
- position: sticky
is currently experimental and not supported in IE.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…