Reputation: 1231
I want to push the footer to the bottom of the page and since the page doesn't have much content the footer floats up and doesn't move to the bottom.
I tried positioning my footer as a fixed element as a workaround and it works but it doesn't in this condition:
In this dimension the footer behaves like you see and it is perfectly expected, hence showing a loophole in my workaround.
This is the website's address: https://n-ii-ma.github.io/Portfolio-Website/contact.html
These are the codes for that part:
/* Contact Footer */
.contact-footer {
position: fixed;
bottom: 10px;
left: 0;
right: 0;
}
<body>
<header>
<h1 class="main-title">Nima's Portfolio</h1>
<nav class="navigation">
<ul>
<li>
<a href="./index.html">Home</a>
</li>
<li>
<a href="./index.html#projects">Projects</a>
</li>
<li>
<a href="./contact.html">Contact Me</a>
</li>
</ul>
</nav>
</header>
<main>
<section class="contact-section">
<h2>Contact Me</h2>
<p>Use the links below to contact me and I'll reach out to you as soon as possible</p>
<div class="links">
<a href="https://github.com/n-ii-ma" target="_blank">
<i class="fab fa-github fa-3x"></i>
</a>
<a href="#">
<i class="fas fa-envelope-square fa-3x"></i>
</a>
</div>
</section>
</main>
<footer class="contact-footer">© All Rights Reserved</footer>
</body>
Is there a way for my footer to always stay at the bottom of the page?
Upvotes: 0
Views: 2319
Reputation: 13002
Simple solution that is fully supported is to use Flexbox.
min-height: 100vh
so it spans at least the entire viewports height.margin: 0
box-sizing: border-box
display: flex
.flex-direction: column
margin-top: auto;
. That will push the footer to the bottom of the page if the page content is less then the viewport height.body {
margin: 0;
padding: 8px;
box-sizing: border-box;
min-height: 100vh;
display: flex;
flex-direction: column;
}
footer {
margin-top: auto;
}
<body>
<header>
<h1 class="main-title">Nima's Portfolio</h1>
<nav class="navigation">
<ul>
<li>
<a href="./index.html">Home</a>
</li>
<li>
<a href="./index.html#projects">Projects</a>
</li>
<li>
<a href="./contact.html">Contact Me</a>
</li>
</ul>
</nav>
</header>
<main>
<section class="contact-section">
<h2>Contact Me</h2>
<p>Use the links below to contact me and I'll reach out to you as soon as possible</p>
<div class="links">
<a href="https://github.com/n-ii-ma" target="_blank">
<i class="fab fa-github fa-3x"></i>
</a>
<a href="#">
<i class="fas fa-envelope-square fa-3x"></i>
</a>
</div>
</section>
</main>
<footer class="contact-footer">© All Rights Reserved</footer>
</body>
Upvotes: 2