Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which unit of measurement is best for webpage layouts, px, percentages, or ems? [duplicate]

Possible Duplicate:
what is the difference px,em and ex?

I have a question for all the coding geniuses on StackOverflow. I am a newbie, and I am about to start building my third website. Being that I had some problems with the layouts of my first two websites, I am asking this question before I start on my third:

What measurement is it best to use for the css elements? Percents,EM's or Px?

Which form of measurement will ensure that I have a site that will not get distorted on different browser sizes/resolutions? Is there anything else that I have to be careful of when building my site so that it will not get distorted when a user zooms, or looks at the site from a different browser size/ resolution? (as was he case on my other sites)

Thanks for your time, guys. Any help would be greatly appreciated!! Thank you.

like image 849
suavedesign Avatar asked Jan 21 '26 19:01

suavedesign


1 Answers

Whichever is easier for you to work with.

Modern browsers (i.e. everything in use today except for IE6 and IE7) have a concept of "CSS pixels" which is different from "actual pixels," so e.g. zooming changes the size of a "CSS pixel." Fonts will scale just fine; if you say the font is 14px, it will start out that way, but if the user zooms it'll get bigger. Thus, if it's easy for you to measure in pixels, for example to size page elements relative to an image of a given pixel size, you should do pixels.

Sometimes you want to size things relative to text, though. If the width of an em-dash is a useful measurement, somewhat representing the "longest possible character," go ahead and use ems.

And finally, if you're trying for a fluid layout, percentages can be great: a gradient that starts fading 50% across the page is often what you want, as opposed to one that starts fading after some fit number of pixels. Even if you're not fluid, and the width of your container is fixed to e.g. 900px, it's still often useful to say "this goes at the 50% mark" or "I have one thing at the 33% mark and one at the 66% mark." That's much easier to work with than figuring out what the corresponding pixel offset is every time, and makes your intent clearer to anyone reading your code.

like image 156
Domenic Avatar answered Jan 23 '26 08:01

Domenic