January 14, 2012

CSS Sizing Advice: %, REMS, and EMs

2 comments    |   Related thoughts:

An interesting blog post – Measuring and sizing UIs, 2011-style — over at CSS Wizardry provides up-to-date advice for CSS measurements. In a nutshell, the post advises web designers to abandon pixel values except in a few cases (like CSS-sprites), and use %, Rems, or ems. In particular it suggests:

.wrapper {
  max-width: 1240px;
}
  1. Steve S. says:

    My biggest issue with percentage based layouts is that the floats fall apart when they contain an image. If the browser resolution isn’t high enough, there’s not enough room for the picture, for example when the user resizes the browser window.

    • Dave McFarland says:

      That’s a good point, and with mobile devices (and smaller screens) becoming more common the situation you describe is easy to get into. One of the most popular solutions to this problem now is “Responsive Web Design.” Using a combination of CSS media queries, flexible grids (that’s the percentage-based layout stuff), and flexible images and media you can address the problem with images not fitting within smaller screen sizes. Sitepoint has a basic introduction to responsive web design. See The Boston Globe web site for an example of responsive web design (make sure you resize your browser window so that it’s as thin as it can get.)