且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

“&"是什么意思?CSS 中的伪元素之前是什么意思?

更新时间:2023-01-24 13:02:58

那是 LESS,而不是 CSS.

That's LESS, not CSS.

此语法允许您嵌套选择器修饰符.

This syntax allows you to nest selector modifiers.

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

将编译为:

.clearfix:before {
  content: '';
}

使用&,嵌套选择器编译为.clearfix:before.
没有它,他们编译为 .clearfix :before.

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