Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,567 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!