css中大于符号是什么意思

css中大于符号是css3特有的子元素选择器,子元素选择器只能选择作为某元素子元素的元素,其语法如“h1 > strong {color:red;}”。



推荐:《css视频教程》

css中大于符号(“>”)代表的是css3特有的子元素选择器(element>element )。子元素选择器(Child selectors)只能选择作为某元素子元素的元素。

如果你不希望选择任意的后代元素,而是希望缩小范围,只选择某个元素的子元素,请使用子元素选择器(Child selector)。

例如,如果您希望选择只作为 h1 元素子元素的 strong 元素,可以这样写:

1

h1 > strong {color:red;}

这个规则会把第一个 h1 下面的两个 strong 元素变为红色,但是第二个 h1 中的 strong 不受影响:

示例:

1

2

3

4

5

6

7

8

9

10

11

12












 

This is very very important.


 

This is really very important.







css 子元素选择器

element>element 选择器用于选择特定父元素。

注意:元素没有被选中是不能直接指定父级的子元素。

子选择器使用了大于号(子结合符)。

子结合符两边可以有空白符,这是可选的。因此,以下写法都没有问题:

1

2

3

4

h1 > strong

h1> strong

h1 >strong

h1>strong

如果从右向左读,选择器 h1 > strong 可以解释为“选择作为 h1 元素子元素的所有 strong 元素”。

猜你喜欢

转载自blog.csdn.net/zy17822307856/article/details/112661891