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

Sarah S
Sarah S
3,267 Points

Why is 3rem different between these two CSS sections?

I have the below code in a website I'm working on for practice. Can someone explain to me why the 3rem is showing up as different sizes between the two? I only ever have one of them commented in at a time. So, if the h1 font-size is commented in, the main-header one is commented out and vice versa. It was my understanding that rem multiplies against the font size of the <html> tag, so shouldn't 3rem always be the same regardless of where it is used? Any information you can provide would be much appreciated! Thanks!

<header class="main-header"> <h1>Title</h1> </header>

h1 { font-size: 3rem; text-align: center; }

.main-header { padding-top: 200px; height: 700px; background: linear-gradient(to bottom, transparent 20%, #97ed8a), url('../images/city.jpg') no-repeat center; background-size: cover; color: #01271c; font-size: 3rem; }

1 Answer

Steven Parker
Steven Parker
231,248 Points

When you set the h1 explicitly you get 3rem, but when you set only the "main-header" to 3rem the h1 is by default 2em so you get the equivalent of 6rem. If you had anything visible in the header that was not part of the h1 it would be displayed at 3rem.

Sarah S
Sarah S
3,267 Points

Thank you so so much! I find rem and em a bit tricky and that helped clear things up a lot.