What does the '&' selector select?

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

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

3条回答
  •  感动是毒
    2021-02-06 21:54

    One usage that is less widely known is you can add the ampersand to the end of a style so the parent selector becomes the child.

    eg:

     h3
       font-size: 20px
       margin-bottom: 10px
    
     .some-parent-selector &
       font-size: 24px
       margin-bottom: 20px
    

    becomes,

      h3 {
        font-size: 20px;
        margin-bottom: 10px;
      }
    
      .some-parent-selector h3 {
        font-size: 24px;
        margin-bottom: 20px;
      }
    

    you can read more about & use here

    http://thesassway.com/intermediate/referencing-parent-selectors-using-ampersand

提交回复
热议问题