I am working on a wordpress website and want to implement a footer that is pushed to the lower edge of the browser screen if the content get´s smaller than the browser screen hight.
I want to use this approach:
Now I am looking for an effective way with CSS and HTML to implement that for 2 different page types and one media query breakpoint. I am using Code Snippets Plugin to place my code:
Now with this nothing happens… I kind of think there is still some syntax issues I can not find… or some addressing not working properly… any idea what´s wrong here…
Bear in mind that making a sticky footer like that is outdated and prone to break. There is no need for magic numbers or accounting for header and footer height as flex will do that automatically and in a responsive setting so you wouldn’t need media queries for different heigh headers and footers. However you do need the right structure to start with rather than trying to bolt things on at the end.
Here is a minimalist example of the best sticky footer in the world.
You don’t need any of that stuff you were playing with and it will completely automatic regardless of header and footer heights.
It will need testing though as your page is a monster page for what could be accomplished in a few lines of code. I know wordpress sites are verbose and sometimes a necessary evil but wow how many divs do you really need.
There may also be issues as you have some sort of scrolling/motion routines that are changing heights and translating elements on the fly. Not to mention quite a spread of min-heights with vh units in place.
Paul! That´s amazing!! Thanks so much! Your short snippet just works perfectly!
And yes. I know that looking at the code must be horrifying for a pro coder. As I come from a complete no code perspective and just use tools that let me avoid writing code, I only slowly start to learn what I can exchange with just a few lines of code.
So keep up the faith with me I am looking forward to learn more about the true religion!
Those pages have the right structure but I couldn’t find unique classes on the elements so if these classes are dynamic or change you will need to use a unique class. Basically you just have to apply the flex rule to the middle element wrapper which makes it push the footer down and the header up.
/*imprint page*/
.elementor.elementor-36.dce-elementor-post-36 {
flex:1 0 0%;
}
.elementor-36 .elementor-element.elementor-element-5dcced94{
padding-bottom:5px; /* you had 20% bottom padding which seems to be a waste of space*/
}
/* privacy page */
.elementor.elementor-3.dce-elementor-post-3{
flex:1 0 0%;
}
To explain the method a bit the the structure needed is that you have three direct children of #wrap. e.g. Header, main and footer. Then the main middle element gets the flex:1 0 0% and that automatically forces the footer to the bottom of #wrap which has a min-height of 100vh.