Forum Moderators: not2easy

Message Too Old, No Replies

What does this selector do?

Inquiry on the technical use of a "*" as a selector in CSS.

         

rezachemical

4:19 am on Apr 4, 2006 (gmt 0)

10+ Year Member



* {
padding: 0;
margin: 0;
}

what can u use in the html to use this "wild card". i suspect it works somewhat like the size attributes for things like framesets. but i wna make sure

Setek

4:37 am on Apr 4, 2006 (gmt 0)

10+ Year Member



Actually, the * is more of a reference like CLI - it means "any and every element", not like in framesets where it means "fill up the rest of the space".

When you apply

margin: 0px;
and
padding: 0px;
to *, it applies it to -every element- in existence.

bedlam

5:36 am on Apr 4, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



When you apply margin: 0px; and padding: 0px; to *, it applies it to -every element- in existence.

Correct! The implied question though is 'why apply styles to every element?'

The example you've both used is instructive; the wildcard is typically used to universally set non-inherited styles to a certain value--the same strategy would not be particularly useful with a property such as 'color' which might as well be declared for the body element and inherited by all its child elements (i.e. everything).

The most compelling reason I know of for using the wildcard to globally set property values is to override different useragents' default styles--styles such as the very different default styles applied to ul and li elements in IE and Mozilla based browsers.

Obviously, this means you will commonly see the wildcard element used in conjunction with a new set of default values for various other elements...

-b