What does the '&' selector select?

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

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

3条回答
  •  心在旅途
    2021-02-06 21:56

    Exactly. In Sass you could have something like this...

     div {
        background: green;
    
        p {
            background: red;
    
            &:hover {
                background: blue;
            }
    
            &:active {
               background: blue; 
            }
        }   
    }
    

    ...which when converted to CSS would become this:

    div {
        background: green;
    }
    
    div p {
        background: red;
    }
    
    div p:hover {
        background: blue;
    }
    
    div p:active {
        blue;
    }
    

    Edit: from &hover: to &:hover

提交回复
热议问题