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!

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.

In order to get the em equivalent for margin, do we have to divide with the font size value only?

The video states, in order to get the em equivalent value for margin we have to divide it with the value we use to get the em equivalent to font-size. My question is, does it have to be the font-size or is the property that has an em equivalent, or if there isn't do we divide it with the default px to get the em equivalent for margin?

(I stopped at this specific part, because it was quite confusing. I assume the rest of the video might clarify, but still wanted to ask.)

This part is pretty confusing. I didn't understand it the first time through either.

The 'em' value is simply "relative to the current element's font size (in pixels)"

So if the current element has a font-size of 10px, setting a property (margin-bottom, in the video example) to .5em is the same as setting that property to 5px.

The math this instructor is using is: If I know I want my margin property to be X pixels, and the font-size property is Y pixels, then X/Y gives me the em value to set for the property. I don't think this is how you would commonly use em values in the real world, but for the purposes of this course it (almost) explains it well.

The extremely confusing part is that he has defined font-size with another em value. When you give font-size an em value, then it is relative to whatever the default font-size is (usually 16px). At this point, you need to know what font-size has been redefined to in order to calculate the em value in the way he describes. However, other properties will still respond to em values as relative to the current pixel value of font-size.