What does an “&” before a pseudo element in CSS mean?

后端 未结 3 1445
后悔当初
后悔当初 2020-12-02 11:59

In the following CSS taken from Twitter Bootstrap what does the ampersand (&) character mean?

.clearfix {
  *zoom: 1;
  &:before,
  &:after {
            


        
3条回答
  •  [愿得一人]
    2020-12-02 12:29

    That's LESS, not CSS.

    This syntax allows you nest nest selector modifiers.

    .clearfix { 
      &:before {
        content: '';
      }
    }
    

    Will compile to:

    .clearfix:before {
      content: '';
    }
    

    With the &, the nested selectors compile to .clearfix:before.
    Without it, they compile to .clearfix :before.

提交回复
热议问题