Why do browsers match CSS selectors from right to left?

后端 未结 3 558
半阙折子戏
半阙折子戏 2020-11-22 01:54

CSS Selectors are matched by browser engines from right to left. So they first find the children and then check their parents to see if they match the rest of the parts of t

3条回答
  •  走了就别回头了
    2020-11-22 02:24

    It allows for cascading from the more specific to the less specific. It also allows a short circuit in application. If the more specific rule applies in all aspects that the parent rule applies to, all parent rules are ignored. If there are other bits in the parent, they are applied.

    If you went the other way around, you would format according to parent and then overwrite every time the child has something different. In the long run, this is a lot more work than ignoring items in rules that are already taken care of.

提交回复
热议问题