views:

281

answers:

7

Should the following be shunned, or praised for its simplicity? For the record, I use it in every site I build, but I've noticed it's not present in many main-stream CSS-Reset frameworks...is there a reason they don't use it too?

* { margin:0; padding:0; }

Edit: I was curious about performance, mostly.

A: 

If your intent is to set the padding and margin of every single element, then there should be no problem with that selector.

Squeegy
A: 

There's nothing particularly wrong with it. * is referred to as the "universal selector", and browser support for it is generally considered to be good, though IE does have some obscure bugs, as usual:
http://reference.sitepoint.com/css/universalselector#compatibilitysection

Chad Birch
A: 

I consider it an important first step in building my CSS layouts. It removes a lot of the troublesome default styling of different browsers and allows me to get more browser-independent results.

Of course I couple it with IE's conditional comments to write IE-version-specific divs around my whole page, and use those to work with IE's bugs (as FF et. al. tend to be more accurate to CSS spec).

EDIT - and I've never noticed any performance problems with it.

Jeff
+1: I use this as a mandatory first line (yes, compressed to one single line) in about every single stylesheet i write. It makes everything so much easier later on IMO.
Arve Systad
+2  A: 

The universal selector can slow things down quite a bit, especially on some WAP browsers. Just think about it for a second: it matches every single element in the document tree.

Besides, for most elements, you'll go on and specify a margin/padding that is different from 0 anyway. As in, there's no point in resetting them for all elements to begin with.

RegDwight
Do you have any documentation on this? I've never noticed any performance problems when I've used it.
Jeff
@Jeff: It's pretty widely known - you can look at the effect in firebug, see how many inherits are applied. * considered unsafe.
annakata
Here's a chart: http://www.stevesouders.com/blog/2009/06/18/simplifying-css-selectors/
RegDwight
+3  A: 

Its best NOT to use it as it causes issues with form elements, especially input buttons and select boxes.

See christianmontoya.com

garrow
+1  A: 

Something you definitely don't want to do is use relative sizes with the universal selector. Things get weird really quick if you do. ;-)

For a good baseline to work from, I'd recommend a tried and tested reset stylesheet.

Rytmis
+1  A: 

I once did some performance testing between the * {margin:0;padding:0}, Eric Meyer's reset, the YUI reset and no CSS at all. The performance difference was negligible.

That said, I now use Eric Meyer's reset so I don't lose the formatting on input buttons which actually makes buttons easier to style cross-browser.

Emily