Welcome to the Treehouse Community
Looking to learn something new?
Ben Brenton266 Points
em 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?
Thas EagansCourses Plus Student 2,533 Points
Em 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.