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.

范例

CSS

* [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;
}
					

HTML

<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.
推荐 初始定义

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
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

图例

完整支持

完整支持

元数据

  • 最后修改: