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 trialBen Brenton
266 Pointsem vs px for multi-platform use
For a project which is to be used on computer, tablets, phones etc., surely em is better to use as it adjusts with the screen it is on, rather than pixel, which is more defined? Is this correct, and which would I be better using? Also, if this is indeed a correct way of looking at it, why would you use both values in your CSS? Surely you would go with one or the other?
1 Answer
Thas Eagans
Courses Plus Student 2,533 PointsEm is relative, whereas PX kind of locks you into a fixed measurement. What I sometimes do is use PX in a fluid design when i want the spacing or margin to remain fixed regardless of what size screen its on. For instance.... I want div 1 to have a 20px top margin from div 2.
I actually prefer to use rem instead of em. Em is based on its parent element, whereas rem is based on the root element. This prevents some unnecessary headaches if a parent container changes it's font size.
</TREagans>
Ben Brenton
266 PointsBen Brenton
266 PointsThank you for clearing that up for me!