What does the '&' selector select?

前端 未结 3 1770
被撕碎了的回忆
被撕碎了的回忆 2021-02-06 20:56

In this codepen there is a css selector &:hover what does that selector match?

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-06 21:46

    I believe the ampersand is a Sass feature. From the docs:

    Referencing Parent Selectors: &

    Sometimes it’s useful to use a nested rule’s parent selector in other ways than the default. For instance, you might want to have special styles for when that selector is hovered over or for when the body element has a certain class. In these cases, you can explicitly specify where the parent selector should be inserted using the & character.

提交回复
热议问题