概述

当使用 选择符 (这里代表一个空格,更确切的说是一个或多个的空白字符) 连接两个元素时使得该选择器可以只匹配那些由第一个元素作为祖先元素的所有第二个元素(后代元素) . 后代选择器与 子选择器 很相似, 但是后代选择器不需要相匹配元素之间要有严格的父子关系.

语法

元素1 元素2 {样式声明 }

示例

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

当上面的CSS作用于下面的HTML时:

<div>
  <span>Span 1.
    <span>Span 2.</span>
  </span>
</div>
<span>Span 3.</span>

会产生下面的效果:

Span 1. Span 2.
Span 3.

规范

Specification Status Comment
CSS Selectors Level 3 Recommendation  
CSS 2.1 Recommendation  
CSS 1 Recommendation  

浏览器兼容性

Browser compatibility

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support1121 Yes Yes Yes
A >> B syntax No No No No No10
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support Yes Yes Yes4 Yes Yes Yes
A >> B syntax No No No No No10 No

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support (Yes) (Yes) (Yes) (Yes) (Yes)
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support ? ? ? ? ?

相关

文档标签和贡献者

标签: 
此页面的贡献者: RainSlide, fscholz, teoli, alimon
最后编辑者: RainSlide,