child combinator ( > ) is placed between two CSS selectors. It matches only those elements matched by the second selector that are the direct children of elements matched by the first.

/* List items that are children of the "my-things" list */
ul.my-things > li {
  margin: 2em;
}
					

Elements matched by the second selector must be the immediate children of the elements matched by the first selector. This is stricter than the descendant combinator , which matches all elements matched by the second selector for which there exists an ancestor element matched by the first selector, regardless of the number of "hops" up the DOM.

句法

selector1 > selector2 { style properties }
					

范例

CSS

span {
  background-color: white;
}
div > span {
  background-color: DodgerBlue;
}
					

HTML

<div>
  <span>Span #1, in the div.
    <span>Span #2, in the span that's in the div.</span>
  </span>
</div>
<span>Span #3, not in the div at all.</span>
					

结果

规范

规范 状态 注释
Selectors Level 4
The definition of 'child combinator' in that specification.
工作草案
Selectors Level 3
The definition of 'child combinators' in that specification.
推荐 无变化。
CSS Level 2 (Revision 1)
The definition of 'child selectors' 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
Child combinator ( A > B ) Chrome 完整支持 1 Edge 完整支持 12 Firefox 完整支持 1 IE 完整支持 7 Opera 完整支持 4 Safari 完整支持 1 WebView Android 完整支持 ≤37 Chrome Android 完整支持 18 Firefox Android 完整支持 4 Opera Android 完整支持 10.1 Safari iOS 完整支持 1 Samsung Internet Android 完整支持 1.0

图例

完整支持

完整支持

另请参阅

元数据

  • 最后修改: