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 Modular CSS with Sass Getting Modular with Mixins and Functions Pixels to Em Function

Sidney François
Sidney François
2,092 Points

Why/how is the _base.scss line-height calculated?

Hey everyone,

I have a rather unspectacular question.

When modifying _base.scss we set font-sizes and margins using the em function. So far so good.

But I don't understand for what reason the line-height is calculated by dividing 46px by 42px. I have watched that part of the video several times but I just don't see (the probably obvious) reason for it?

Thank you.

1 Answer

Wayne Priestley
Wayne Priestley
19,579 Points

Hi Sidney,

Calculating line hight and anything else to do with typography can get extremely complicated if you choose to go down that rabbit hole, using golden ratio etc. Spend a little time googling the math behind it all and you'll soon see.

But to answer your question, you can generally use 1.1 as a way to calculate line height, so the 46 / 1.1 = 41.818181 etc, rounded up to 42.

And vice versa 46 / 42 = 1.0952 rounded up to 1.1

So I'm presuming the 42 was a pixel size for a h1 and you get a line height of 46 or 1.1em.

Now I think I have that correct, but I tend to go on what looks better to me.

Sidney François
Sidney François
2,092 Points

Oh, I see. I just didn't understand that that was what he was going for–but now I see. Thank you so much for getting back to me!