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

SAMUEL LAWRENCE
PLUS
SAMUEL LAWRENCE
Courses Plus Student 8,447 Points

What is the highest value of em?

Hi guys I was wondering if there is a highest value for the em unit of measure? you know % is 100% . So you can have a relative % inside another relative %. what I mean is. If you set a container's width to be 80% you can have two smaller percentages inside of it say, 20%, 40% and 20% and they will always be relative to the 80% parent container which is relative to the html container of 100%.

If you wanted to use ems what would be the equivalent to 100% because em is also a relative unit. for pixels I know how to calculate the ems. but what about container width? I asked because many times Guil Hernandez set the padding of the wrapper div to 1.5em. But some times I find it's too much or not enough and I just guess a value until it looks good. What if I wanted a specific value like say I wanted the padding to be 5%. How would I calculate that exact percentage?

Thanks

2 Answers

Matthew Long
Matthew Long
28,407 Points

An em is relative to font size. Where a percent is relative to the nearest parent percent like you described.

SAMUEL LAWRENCE
SAMUEL LAWRENCE
Courses Plus Student 8,447 Points

Thanks for the reply Matthew Long but it's not only relative to font size because Guil Hernandez has used it many times to set the padding of a container..

Also line-height is usually a unit less value, however Nick Pettit have used ems for line-height. That's why I'd like to know if there is a way to convert it to % or if there is an equivalent 100% em value. He has set line-height to 0.8em.

Matthew Long
Matthew Long
28,407 Points

An em is relative to font-size. This doesn't mean that it can only be used to set the font-size property. It means that the size of an em is relative to font-size. An em can be used in many places and for many things, but the value is relative to font-size. Sorry for any confusion. Maybe this will help you: the power of em units.

In the end I suppose you can technically convert an em to a percent, but this would still depend on the font-size. I found this calculator where you can set the font-size and it will give you a conversion table. Maybe this will demonstrate how it is relative to font-size too.

SAMUEL LAWRENCE
PLUS
SAMUEL LAWRENCE
Courses Plus Student 8,447 Points

Thank you very much. I think I follow you. Thanks for the conversion calculator. Helps a lot.