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 CSS Layout Basics Getting Started with CSS Layout Creating a Sticky Footer

Jim Andrews
Jim Andrews
5,967 Points

Can we reference the footer as a variable in the calc() function rather than declare it's actual height?

In other words, if we later change the size of the footer, it will break this equation. Is there a way of calling out the footer height as a variable? Like...

calc(100vh - footerHeight)

where footerHeight is equal to whatever the height of that element is? So if we go in and change the height in the CSS we don't need to change this equation.

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Jim Andrews ! Sure, there's a way. The best solution would probably be to make a CSS variable and set the height of the footer to that variable and use it yet again in the calc(). I'm not sure if this workshop has made it to be part of one of the "tracks" yet or not as I believe it is relatively new, but you can find a 37 minute workshop with Guil here.

CSS variables are great and can save you tons of time and hunting and searching for values that would need to be changed multiple places. I cannot recommend it highly enough.

Hope this helps! :sparkles: