mozilla

Revision 6515 of Universal selectors

  • Revision slug: CSS/Universal_selectors
  • Revision title: Universal selectors
  • Revision id: 6515
  • Created:
  • Creator: FredB
  • Is current revision? No
  • Comment 20 words added, 2 words removed

Revision Content

{{ CSSRef() }}

Summary

An Asterisk (*) is the universal selector for CSS. It matches a single element of any type. Omitting the Asterisk with simple selectors has the same effect. For instance, *.warning and .warning are considered equal.

In CSS 3 Asterisk (*) may be used in combination with namespace

  • ns|* - matches all elements in namespace ns
  • *|* - matches all elements
  • |* - matches all elements without any declared namespace

Examples

*[lang=en]{color:green;}
*.warning {color:red;}
*#maincontent {border: 1px solid blue;

...where...

<p class="warning">
  <span lang="en-us">A green span</span> in a red paragraph.
</p>
<p id="maincontent" lang="en-gb">
  <span class="warning">A red span</span> in a green paragraph.
</p>

...should look like

A green span in a red paragraph.

A red span in a green paragraph (with a border.)

Notes

Authors are discouraged from using the universal selector as it is the most expensive CSS selector in terms of Webpage Performance.

Specifications

Browser compatibility

Browser Lowest Version
Internet Explorer ?
Firefox 1
Netscape ?
Opera ?
Safari ?

See also

{{ languages( { "fr": "fr/CSS/Sélecteurs_universels" }) }}

Revision Source

<p>{{ CSSRef() }}</p>
<h2>Summary</h2>
<p>An Asterisk (*) is the universal selector for CSS. It matches a single element of any type. Omitting the Asterisk with simple selectors has the same effect. For instance, *.warning and .warning are considered equal.</p>
<p>In CSS 3 Asterisk (*) may be used in combination with namespace</p>
<ul> <li>ns|* - matches all elements in namespace ns</li> <li>*|* - matches all elements</li> <li>|* - matches all elements without any declared namespace</li>
</ul>
<h3 name="Examples">Examples</h3>
<pre class="brush: css">*[lang=en]{color:green;}
*.warning {color:red;}
*#maincontent {border: 1px solid blue;</pre>
<p>...where...</p>
<pre class="brush: html">&lt;p class="warning"&gt;
  &lt;span lang="en-us"&gt;A green span&lt;/span&gt; in a red paragraph.
&lt;/p&gt;
&lt;p id="maincontent" lang="en-gb"&gt;
  &lt;span class="warning"&gt;A red span&lt;/span&gt; in a green paragraph.
&lt;/p&gt;
</pre>
<p>...should look like</p>
<p><span style="color: rgb(0, 255, 0);">A green span</span><span style="color: rgb(255, 0, 0);"> in a red paragraph.</span></p>
<p style="border: 1px solid blue;"><span style="color: rgb(255, 0, 0);">A red span</span><span style="color: rgb(0, 255, 0);"> in a green paragraph (with a border.)</span></p>
<h3 name="Specifications">Notes</h3>
<p>Authors are discouraged from using the universal selector as it is the <a class="external" href="http://www.stevesouders.com/blog/2009/06/18/simplifying-css-selectors/" title="http://www.stevesouders.com/blog/2009/06/18/simplifying-css-selectors/">most expensive CSS selector</a> in terms of Webpage Performance.</p>
<h3 name="Specifications">Specifications</h3>
<ul> <li><a class="external" href="http://www.w3.org/TR/REC-CSS2/selector.html#simple-selector">CSS 2</a></li> <li><a class="external" href="http://www.w3.org/TR/css3-selectors/">CSS 3</a></li>
</ul>
<h3 name="Browser_compatibility">Browser compatibility</h3>
<table class="standard-table"> <tbody> <tr> <th>Browser</th> <th>Lowest Version</th> </tr> <tr> <td>Internet Explorer</td> <td>?</td> </tr> <tr> <td>Firefox</td> <td>1</td> </tr> <tr> <td>Netscape</td> <td>?</td> </tr> <tr> <td>Opera</td> <td>?</td> </tr> <tr> <td>Safari</td> <td>?</td> </tr> </tbody>
</table>
<h2>See also</h2>
<p>{{ languages( { "fr": "fr/CSS/Sélecteurs_universels" }) }}</p>
Revert to this revision