Bartłomiej Szałach
Bartłomiej Szałach

Reputation: 2453

Universal Selector CSS

Is it a good habit to use in CSS universal selector to set some properies of many elements. I mean, for instance:

* {margin: 0; padding: 0;}

Maybe default values are logical and we shouldn't change them all in the one line.

Upvotes: 0

Views: 455

Answers (3)

Sean Ryan
Sean Ryan

Reputation: 6056

This issue with the universal selector is that you are going to remove some potentially useful browser defaults on some elements, just to have to explicitly add them back at a later time.

In other words, a user is going to have to download a CSS style to put back padding or margin on an element that already had perfectly acceptable padding or margin without any download.

If you are looking to make elements render the same across all browsers, I would suggest you check out normalize.css, which tries to keep as many browser defaults in place as it can.

Upvotes: 2

runningRhetoric
runningRhetoric

Reputation: 2581

The universal selector is good for troubleshooting. If absolutely stumped on elements that are causing overflow issues I'll do * {border:1px solid pink}. Be sure to remove once troubleshooting is complete.

Upvotes: 2

Mechwd
Mechwd

Reputation: 400

The universal selector does cause a performance issue so try to avoid it.

Upvotes: 1

Related Questions