I want to stick footer at the bottom of the page even when there is no content. When there is enough content, the footer should move to the end of the page.
I'm learning flexbox and tried doing so using flexbox. But it isn't working.
html {
height: 100%;
}
body,
#root {
display: flex;
flex-direction: column;
}
.app {
text-align: center;
}
.header,
.footer {
background: #282c34;
flex-shrink: 0;
color: white;
}
.main {
flex: 1 0 auto;
}
a {
text-decoration: none;
color: #42A5F5;
padding: 20px 0;
}
<div class="root">
<div class="app">
<div class="header">
<a href="#">Logo</a>
<h1>Application Name</h1>
<nav>
<a href="#" class="navItem">Link1</a>
<a href="#" class="navItem">Link2</a>
<a href="#" class="navItem">Link3</a>
</nav>
</div>
<div class="main">
<p class="description">Small Description</p>
<div class="search">
<input type="text" />
<p>Please Insert Search Query</p>
</div>
<div class="searchResult"></div>
</div>
<div class="footer">
<div class="about">Some Random Company</div>
<div class="footerLink">Contact</div>
<div class="social">Twitter</div>
</div>
</div>
</div>
I want to know why it's not working and the mistake that I'm doing here. I know this question has been asked before. I just want to know, what's wrong with my code so that I can write better CSS after understanding it.
Also, here is the updated jsFiddle