子选择器和后代选择器


子选择器

子选择器选择作为指定元素的子元素的所有元素。

以下示例选择作为

元素的子元素的所有

元素:






Child Selector

The child selector (>) selects all elements that are the children of a specified element.


Paragraph 1 in the div.


Paragraph 2 in the div.


Paragraph 3 in the div.

 /* 所以这一行不是黄色的*/

Paragraph 4. Not in a div.


Paragraph 5. Not in a div.


 后代选择器

后代选择器匹配作为指定元素的后代的所有元素。

以下示例选择

元素内的所有

元素: 






Descendant Selector

The descendant selector matches all elements that are descendants of a specified element.


Paragraph 1 in the div.


Paragraph 2 in the div.


Paragraph 3 in the div.

 /* 所以这一行是黄色的*/

Paragraph 4. Not in a div.


Paragraph 5. Not in a div.