Ever wanted to have a footer that's stuck to the bottom, but will push down if the content is bigger?
To demonstrate I've created this image.
W...
For further actions, you may consider blocking this person and/or reporting abuse
In some cases, I recommend to use height 100% instead of 100vh as vh might cause issues with the chrome nav bar on mobile
Ah good point Peter! Didn't account for that indeed.
There is a fix for the 100vh on mobile though.
Oh - can you elaborate on that fix?
Sure CSS-tricks has a very good article on that:
css-tricks.com/css-fix-for-100vh-i...
This was a thing that I dealt with a few weeks back on my own blog. I fixed it with JS but I was ashamed of the solution. Thanks for this, I will apply this one instead of following.
Hi Ertan, It's cool you found your own solutions as well, it's what we do as developers.
There are always different quicker solutions.
is there some reason not to use
position: fixed
anymore?You can however in this example I didn't want the footer to be always visible, which it would be with fixed.
It's a different solution and imagines those big-ass footers these days, don't want that as a fixed block.
thanks
Margin collapsing won't work on a flexbox based layout.
I think I will stick to the old fixed footer way and add a empty div to occupy spaces for the footer.
What exactly do you mean by margin collapsing? in which sense?
This is great, thanks for sharing! I’ll try to use this in my next project.
Awesome Andrew, if you want to you can share the end-result always cool to see what people use it for 🤟
What about the position sticky? Today its browser support is more than 95%.
Sticky is a valid solution same as fixed.
Just remember the footer will always be visible, which I didn't want for this example.
If that's what you want it's a propper solution though!
Perfect!
Thats a good idea Edson Jr.! How will you account for the footer that keeps being visible on the bottom of your screen though?
Related:
How to create a sticky Website footer in 5 different ways
Habdul Hazeez ・ Jun 30 ・ 6 min read