The CSS
universal selector
(
*
) matches elements of any type.
/* Selects all elements */
* {
color: green;
}
Beginning with CSS3, the asterisk may be used in combination with
namespaces
:
ns|*
- matches all elements in namespace
ns
*|*
- matches all elements
|*
- matches all elements without any declared namespace
* { style properties }
The asterisk is optional with simple selectors. For instance,
*.warning
and
.warning
are equivalent.
* [lang^=en] {
color: green;
}
*.warning {
color: red;
}
*#maincontent {
border: 1px solid blue;
}
.floating {
float: left
}
/* automatically clear the next sibling after a floating element */
.floating + * {
clear: left;
}
<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>
| 规范 | 状态 | 注释 |
|---|---|---|
|
Selectors Level 4
The definition of 'universal selector' in that specification. |
工作草案 | No changes |
|
Selectors Level 3
The definition of 'universal selector' in that specification. |
推荐 | Defines behavior regarding namespaces and adds hint that omitting the selector is allowed within pseudo-elements |
|
CSS Level 2 (Revision 1)
The definition of 'universal selector' in that specification. |
推荐 | 初始定义 |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
Universal selector (
*
)
|
Chrome 完整支持 1 | Edge 完整支持 12 | Firefox 完整支持 1 | IE 完整支持 7 | Opera 完整支持 3.5 | Safari 完整支持 1 | WebView Android 完整支持 ≤37 | Chrome Android 完整支持 18 | Firefox Android 完整支持 4 | Opera Android 完整支持 10.1 | Safari iOS 完整支持 1 | Samsung Internet Android 完整支持 1.0 |
Namespaces (
*|*
)
|
Chrome 完整支持 1 | Edge 完整支持 12 | Firefox 完整支持 1 | IE 完整支持 9 | Opera 完整支持 8 | Safari 完整支持 1.3 | WebView Android 完整支持 ≤37 | Chrome Android 完整支持 18 | Firefox Android 完整支持 4 | Opera Android 完整支持 10.1 | Safari iOS 完整支持 1 | Samsung Internet Android 完整支持 1.0 |
完整支持
Type selectors
Class selectors
ID selectors
Universal selectors
Attribute selectors
:active
:any-link
:checked
:blank
:default
:defined
:dir()
:disabled
:empty
:enabled
:first
:first-child
:first-of-type
:fullscreen
:focus
:focus-visible
:focus-within
:has()
:host()
:host-context()
:hover
:indeterminate
:in-range
:invalid
:is() (:matches(), :any())
:lang()
:last-child
:last-of-type
:left
:link
:not()
:nth-child()
:nth-last-child()
:nth-last-of-type()
:nth-of-type()
:only-child
:only-of-type
:optional
:out-of-range
:placeholder-shown
:read-only
:read-write
:required
:right
:root
:scope
:target
:valid
:visited
:where()
::-moz-progress-bar
::-moz-range-progress
::-moz-range-thumb
::-moz-range-track
::-webkit-progress-bar
::-webkit-progress-value
::-webkit-slider-runnable-track
::-webkit-slider-thumb
::after (:after)
::backdrop
::before (:before)
::cue
::cue-region
::first-letter (:first-letter)
::first-line (:first-line)
::grammar-error
::marker
::part()
::placeholder
::selection
::slotted()
::spelling-error