Universal selector * and pseudo elements

后端 未结 2 1682
青春惊慌失措
青春惊慌失措 2020-11-28 09:26

Does the universal selector * affect pseudo elements like :before and :after?

Let me use an example:

When doing this:

2条回答
  •  忘掉有多难
    2020-11-28 09:52

    I can only cite from the specification:

    The universal selector, written "*", matches the name of any element type. It matches any single element in the document tree.

    Element types are for example span and div.

    Since pseudo elements don't have an "element type" and are not part of the document tree, it looks like the answer is no, it does not include pseudo elements.

    However, since pseudo elements inherit the CSS properties from their "parent" (at least the ones that are inheritable) and the universal selector also affects the parent, it indirectly affects the pseudo elements.

    Example

    • the color is inherited
    • the border style is not and the ::before element doesn't have a border

提交回复
热议问题