What is the logic behind sibling selectors * + * and * ~ *?

前端 未结 3 943
难免孤独
难免孤独 2020-12-30 23:56

For this question I\'m using the following markup:


    

1

3条回答
  •  轮回少年
    2020-12-31 00:47

    That's an error in your test case. As you would expect, none of the selectors match the first paragraph, but the styling from the body cascades to the paragraphs!

    Both * + * and * ~ * match body as it is preceded by a head tag. Thus, it receives text-decoration:underline and font-style:italic. That explains why all of the paragraphs are both underlined and italicised.

提交回复
热议问题