17

In my stylesheet I use em for font sizes.

Is it bad practice to use this for padding and margin as well so that when the font scales the margin and padding will scale with it?

AJM
  • 32,054
  • 48
  • 155
  • 243

4 Answers4

4

I don't think that its a bad practice, but I don't think that most of developers will use it nowadays: some thought on it:

mas-designs
  • 7,498
  • 1
  • 31
  • 56
3

It totally depends on your need. Em should be avoided because it depends on the native browser settings, but if you use px then css of the page will be cross browser compatible.

Please refer to this post : Why em instead of px? This post will tell you when to use EM and when PX.

Community
  • 1
  • 1
waseem
  • 89
  • 1
  • 7
2

I don't see how this is wrong?

em is just a way of expressing the measuring method. you can use pixels, em, cm.

also the padding of a div will be measured the way you put it. so if you write em to the padding it will work just as good as if you put pixels, it's just the value of spacing that varies

dennis
  • 2,000
  • 18
  • 26
0

I usually use em for font size, height, width, padding, and margin. I don't usually mess with line-height, but I'd use em for that too. This of course always depends on what's on the page; gifs, pngs, and jpgs don't usually do so well with ems ;-)

eric
  • 401
  • 3
  • 7