How to keep footer at the bottom of the screen
In order to anchor your footer to the bottom of the screen, tech gurus recommend using CSS Flexbox. Here’s the secret sauce: apply display: flex; flex-direction: column;
to the <body>
, add flex: 1;
to <main>
to gobble up space, and finally margin-top: auto;
to <footer>
to nudge it right down. Here, check it out:
Hocus pocus with Flexbox to keep the footer obedient at the bottom on both short and long pages. Now, plan for a short screenplay with minimal content to ensure your footer's diva antics are kept in check.
Making it cross-browser compatible and responsive
Winning the web browser lottery
How do you have a peace pact for cross-browser compatibility with your footer that includes every opera singer (here's looking at you, Opera)? Testing, of course! Just in case Opera decides to go full diva, you can reel it in with this fix:
Responsiveness is king
To avoid embarrassing footer slip-ups on different devices, media queries can be your knights in shining armor, ensuring the footer behaves like a perfect guest regardless of screen size.
Overlapping isn't just rude in conversations
Now, content is king, and you wouldn't want your king to hide behind your footer, would you? So, a padding-bottom
that suits your <main>
content will save your day.
Remember, if you choose to stick the footer at the bottom with position: fixed;
, ensure the footer stretches out to 100% width like that yoga pose you can't quite master yet. Get your body’s margin to match the footer’s height. That'll keep any content overlap at bay.
Cash in on structured styling
Your footer needs to look fashionable
A defined height gives your footer that high-end bespoke fit. Nothing less for our footer lord!
Positioning is everything
A killer stance is what sets a supermodel apart. Your footer can join those ranks by being positioned to the left of the screen (left: 0;
), holding the stage perfectly regardless of the screen width.
Was this article helpful?