Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS

Need help keeping footer at the bottom of the page.

I want my footer to be at the bottom of the page but for some of my pages it goes into the middle of the page and cuts into the content. The only fix I could find is turning it into a sticky footer by making position: relative to position: fixed but I don't really like the look of the sticky footer. I only want it to be seen if you scroll down all the way to the bottom of the page

HTML: <div class="footer"> <footer class="foot"> PlugIncWW | Built by <a class="me" href="https://twitter.com/realdynobot" target="_blank">Vincent Nguyen</a> <a class="socials" href="https://twitter.com/plugincWW" target="_blank"><i class="fab fa-twitter"></i></a> <a class="socials" href="mailto:pluginc.help@gmail.com"><i class="far fa-envelope"></i></a> </footer> </div> </html>

CSS: /* Footer */ .footer { position: relative; right: 0; bottom: 0; left: 0; background-color: #ffffff; border-top: rgb(201, 198, 198) solid 1px; }

footer { top: 50%; position: relative; bottom: 0; height: 30px; width: 90%; padding: 10px; margin: 0 auto; color: white; top: 50%; }

.foot { color: rgb(102, 102, 102); }

.me { text-decoration: none; color: rgb(0, 155, 202) }

.me:hover { color: rgb(0, 124, 161) }

.socials { color: rgb(94, 94, 94); padding-right: 20px; float: right; transition: color 200ms; }

.socials:hover { color: rgb(0, 155, 202) }

.socials:active { color: rgb(0, 124, 161) }

1 Answer

Sam Gord
Sam Gord
14,084 Points

i think one way of doing this is that if the body element is the parent of the footer element, like this -->

<body>
  <footer></footer>
</body>

then u can give the body element a relative position and the footer an absolute position like this, with a height value defined for body:

body{
 position: relative;
 height: 100vh;
}

footer{
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
}

happy coding ;)

Worked on my home page but on the other pages it now cuts into the header of my page