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
Grace Ji
5,402 Pointscreate a sticky footer
I am trying to make a sticky footer. I set height: (100vh-89px) in the .wrap, but the footer is still floating in the middle. How can I fix it?
Here is my css code
/* =================================
Base Element Styles
==================================== */
* {
box-sizing:border-box;
}
body {
line-height: 1.6;
color: #3a3a3a;
}
a {
color: #000;
text-decoration: none;
}
p {
margin-bottom:0;
}
/* =================================
Base Layout Styles
==================================== */
.name {
margin:0;
}
.wrap {
background-color: tomato;
width: 100%;
margin: 0;
padding-bottom:2rem;
height: calc(100vh-89px);
}
.h1 {
background-color: #4787FF;
padding: 0 1rem;
}
.h2 {
margin: 0 auto;
padding: 0 1rem;
}
.footer {
text-align:center;
margin:0;
background: #6FBFA0;
color: #fff;
padding: 2em 2em;
text-align:center;
bottom:0;
}
/* =================================
Media Queries
==================================== */
@media(min-width: 769px) {
.h1,
.h2{
padding: 0 3rem;
}
}
}
And here is my html code
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Best City Guide</title>
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="wrap">
<div class="h1">
<h1 class="name"><a href="#">Best City Guide</a></h1>
<ul class="main-nav">
<li><a href="#">ice cream</a></li>
<li><a href="#">donuts</a></li>
<li><a href="#">tea</a></li>
<li><a href="#">coffee</a></li>
</ul>
</div>
<div class="h2">
<h2>Welcome!</h2>
<p>Everything in this city is worth waiting in line for.</p>
<p>Cupcake ipsum dolor sit. Amet chocolate cake gummies jelly beans candy bonbon brownie candy. Gingerbread powder muffin. Icing cotton candy. Croissant icing pie ice cream brownie I love cheesecake cookie. Pastry chocolate pastry jelly croissant.</p>
<p>Cake sesame snaps sweet tart candy canes tiramisu I love oat cake chocolate bar. Jelly beans pastry brownie sugar plum pastry bear claw tiramisu tootsie roll. Tootsie roll wafer I love chocolate donuts.</p>
</div>
</div>
<footer class="footer">
<span>©2015 Residents of The Best City Ever.</span>
</footer>
</body>
</html>
2 Answers
Tri Pham
18,671 Pointsyeah, css is not a real programming language and the syntax rules can be a little unforgiving and unexpected. Add proper spacing so it looks like this. height: calc(100vh - 89px);
David Low
13,475 PointsGive the footer a height of 89px and it should stick to the bottom. I think it it's fine to remove the bottom: 0 as well.
Grace Ji
5,402 PointsGrace Ji
5,402 PointsWow! Your tip works instantly! Thank you Tri!!!! YOU ROCK!!!
Simon Fukada
7,767 PointsSimon Fukada
7,767 PointsThank you so much for this!! I was having so much trouble, but your advice fixed my footer!!