I'm starting a new project and considering to use em.
What are the best practices to be followed when using em instead of px (to create a scalable layout).
I would also welcome any pitfalls with this approach and possible solutions to it
I'm starting a new project and considering to use em.
What are the best practices to be followed when using em instead of px (to create a scalable layout).
I would also welcome any pitfalls with this approach and possible solutions to it
The best trick I know is to set the body
text size to 62.5%
. This way any em
value you use will have a direct correlation to px
sizes. Eg 1.2em
= 12px
This is of course assuming the element you are setting the em
size on does not have any parents which have already had their size set, in which case you will need to do some maths to work out the relative size.
You may want to check out a book called "Responsive Web Design". It has some great best practices when it comes to using EMs and %s for layout, type, and images: http://www.abookapart.com/products/responsive-web-design