What does the & mean in an scss selector?

前端 未结 1 419
梦毁少年i
梦毁少年i 2021-02-05 05:45

What does & refer to in an scss selector?


    //Case 1

    .parent {
      & > ul {
        color: red
      }
    }

    //Case 2

    .parent {
          


        
1条回答
  •  醉话见心
    2021-02-05 06:37

    The & is a placeholder for the parent selector:

    .parent {
      & > ul {
        color: red
      }
    }
    

    Is the same like

    .parent > ul {
      color: red
    }
    

    A common use case are pseudo classes, e.g.:

    .link {
      &:hover {
        color: red
      }
    }
    

    A nice explanation with examples can be found on CSS Tricks.

    0 讨论(0)
提交回复
热议问题