Universal Selector
A universal selector (*) selects all elements in a document. For example, the below style rule will make the text of every element in the document red.
* {color:red;}
The concept of CSS reset highlighted by Andrew Krespanis back in 2004 make use of the universal selector to set the margin
and padding
of all elements in a page to 0.
* {
margin: 0;
padding: 0;
}
Universal selector can also be used as a contextual selector. In the example below, the descendants of all ul
elements are selected and their font-sizes set to 12px.
ul * {font-size:12px;}
Also, it can be used in the selection all elements with the same class name. Here, all elements with the class name redtext
are selected
*.redtext {color:red;}
This, however, has the same effect as
.redtext {color:red;}
Likewise, the selection *#some-id
gives the same effect as #some-id
.