From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- files/zh-cn/web/css/child_combinator/index.html | 117 ++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 files/zh-cn/web/css/child_combinator/index.html (limited to 'files/zh-cn/web/css/child_combinator/index.html') diff --git a/files/zh-cn/web/css/child_combinator/index.html b/files/zh-cn/web/css/child_combinator/index.html new file mode 100644 index 0000000000..e161f15dae --- /dev/null +++ b/files/zh-cn/web/css/child_combinator/index.html @@ -0,0 +1,117 @@ +--- +title: 子选择器 +slug: Web/CSS/Child_combinator +tags: + - CSS + - Selectors +translation_of: Web/CSS/Child_combinator +--- +

{{ CSSRef() }}

+ +

概述

+ +

当使用  > 选择符分隔两个元素时,它只会匹配那些作为第一个元素的直接后代(子元素)的第二元素. 与之相比, 当两个元素由 后代选择器 相连时, 它表示匹配存在的所有由第一个元素作为祖先元素(但不一定是父元素)的第二个元素, 无论它在 DOM 中"跳跃" 多少次.

+ +

语法

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

示例

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

当应用与如下标记时:

+ +
<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 a div at all</span>
+
+ +

会得到下面的效果:

+ +

Span 1. In the div. Span 2. In the span that's in the div.
+ Span 3. Not in a div at all.

+ +

规范

+ + + + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
CSS Selectors Level 3{{ Spec2('CSS3 Selectors') }} 
CSS 2.1{{ Spec2('CSS2.1') }} 
+ +

浏览器兼容性

+ +

{{ CompatibilityTable() }}

+ +
+ + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support{{ CompatVersionUnknown() }}{{ CompatVersionUnknown() }}7.0{{ CompatVersionUnknown() }}{{ CompatVersionUnknown() }}
+
+ +
+ + + + + + + + + + + + + + + + + + + +
FeatureAndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic support{{ CompatUnknown() }}{{ CompatUnknown() }}{{ CompatUnknown() }}{{ CompatUnknown() }}{{ CompatUnknown() }}
+
+ +

相关

-- cgit v1.2.3-54-g00ecf