html,
body {
height: 100%;
margin: 0;
html {
background:white;
body {
background:blue;
#main {
height: 92%;
#landing {
display: flex;
align-items: center;
justify-content: center;
height: 100%;
text-align: center;
#landingContent {
width: 20vw;
#footerNav {
height: 8%;
display: flex;
align-items: center;
position: sticky;
top: 0px;
background:red;
color:#fff;
<div id="main">
<div id="landing">
<div id="landingContent">
<h1 class="logo">Logo</h1>
<p id="landingParagraph">Lorem ipsum, paragraph content, etc etc.</p>
<button>Button</button>
<div id="footerNav">
<div id="footerNavContent">
<h1 class="logo">Logo</h1>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
As you can see the logo is already at the bottom of the body so there is no way to make it move as sticky. Also your content is overflowing.
Now if you decrease the height of the main content a bit, you can see a small sticky behavior that will end when the footer will reach the bottom of the blue part (the body
).
html,
body {
height: 100%;
margin: 0;
html {
background:white;
body {
background:blue;
#main {
height: 82%;
#landing {
display: flex;
align-items: center;
justify-content: center;
height: 100%;
text-align: center;
#landingContent {
width: 20vw;
#footerNav {
height: 8%;
display: flex;
align-items: center;
position: sticky;
top: 0px;
background:red;
color:#fff;
<div id="main">
<div id="landing">
<div id="landingContent">
<h1 class="logo">Logo</h1>
<p id="landingParagraph">Lorem ipsum, paragraph content, etc etc.</p>
<button>Button</button>
<div id="footerNav">
<div id="footerNavContent">
<h1 class="logo">Logo</h1>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<div id="landingContent">
<h1 class="logo">Logo</h1>
<p id="landingParagraph">Lorem ipsum, paragraph content, etc etc.</p>
<button>Button</button>
<div id="footerNav">
<div id="footerNavContent">
<h1 class="logo">Logo</h1>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
Related questions for more details/examples:
Why element with position:sticky doesn't stick to the bottom of parent?
What are `scrolling boxes`?
If you specify `bottom: 0` for position: sticky, why is it doing something different from the specs?
I had the same issue, but I needed the height: 100%;
on the parent container. In my case I have a sticky navigation, the content needs to grow to its full length and the footer should always be visible at the end of the page (but with no position attribute).
I fixed it by setting overflow: auto;
to that parent container. Now the parent is still 100% tall but the sticky container inside it, doesn't matter the height limitations.
The support for the use of position: sticky seems to be sort of weak. You can check that in this page:
https://caniuse.com/#search=position%3A%20sticky
If you want a sticky footer, you may use position: absolute, which is supported by every browser. I took your code and created like a mini version of it to illustrate my point regarding position: absolute.
<!doctype html>
<style>
margin: 0;
padding: 0;
.footerNav {
background-color: red;
position: absolute;
bottom: 0;
width: 100%;
height: 100px;
</style>
</head>
<div id="main">
<div id="landing">
<div id="landingContent">
<h1 class="logo">Logo</h1>
<p id="landingParagraph">Lorem ipsum, paragraph content, etc etc.</p>
<button>Button</button>
<div class="footerNav">
<div id="footerNavContent">
<h1 class="logo">Logo</h1>
</body>
Please, notice that I changed id="footerNav" for class="footerNav". I personally favor classes for applying styles. But you can use ids if you still prefer to.
If you want the login page to appear, and then the user to scroll a little bit to see your footer, then you can use the height: 100vh and remove the position absolute from the footer since it will be pushed down below by the main content div. For instance:
<!doctype html>
<style>
margin: 0;
padding: 0;
#main {
height: 100vh;
#footerNav {
background-color: red;
position: relative;
bottom: 0;
width: 100%;
height: 100px;
</style>
</head>
<div id="main">
<div id="landing">
<div id="landingContent">
<h1 class="logo">Logo</h1>
<p id="landingParagraph">Lorem ipsum, paragraph content, etc etc.</p>
<button>Button</button>
<div id="footerNav">
<div id="footerNavContent">
<h1 class="logo">Logo</h1>
</body>
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.