What is the difference between '>' and a space in CSS selectors?

前端 未结 5 658
野性不改
野性不改 2020-11-27 12:30

What\'s the point using this syntax

div.card > div.name

What\'s the difference between this

div.card div.name

5条回答
  •  隐瞒了意图╮
    2020-11-27 13:06

    div.card > div.name matches

    ....
    xxx
    ...
    but it doesn't match
    ....
    ...
    xxx
    ..
    ....

    div.card div.name matches both.

    That is, the > selector makes sure that the selected element on the right side of the > is an immidiate child of the element on its left side.

    The syntax without the > matches any

    that is a descendant (not only a child) of
    .

提交回复
热议问题