html选择器有哪些child,子选择器 | Child selectors

子选择器 | Child selectors

该子元素组合因子(>)被放置在两个CSS选择器之间。仅当第二个选择器所匹配的元素是第一个选择器所匹配的元素的子节点时,该子元素选择器才会匹配那些子元素。

/* List items that are children of the "my-things" list */

ul.my-things > li {

margin: 2em;

}

由第二个选择器匹配的元素必须是由第一个选择器匹配的元素的直接子元素。这比后代选择器(descendant selector)更严格,后者仅要求第一个选择器选择出的元素能匹配第二个选择器选择出的元素的某些祖先节点即可,而不管DOM上“跳”的数量。

语法

selector1 > selector2 { style properties }

实例

CSS

span {

background-color: white;

}

div > span {

background-color: DodgerBlue;

}

HTML

Span #1, in the div.

Span #2, in the span that's in the div.

Span #3, not in the div at all.

结果

规范

Specification

Status

Comment

Selectors Level 4The definition of 'child combinator' in that specification.

Working Draft

Selectors Level 3The definition of 'child combinators' in that specification.

Recommendation

No change.

CSS Level 2 (Revision 1)The definition of 'child selectors' in that specification.

Recommendation

Initial definition.

浏览器兼容性

Feature

Chrome

Edge

Firefox (Gecko)

Internet Explorer

Opera

Safari

Basic support

(Yes)

(Yes)

(Yes)

7.0

(Yes)

(Yes)

Feature

Android

Edge

Firefox Mobile (Gecko)

IE Mobile

Opera Mobile

Safari Mobile

Basic support

?

(Yes)

?

?

?

?

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值