“&"是什么意思?CSS 中的伪元素之前是什么意思? [英] What does an "&" before a pseudo element in CSS mean?

查看:43
本文介绍了“&"是什么意思?CSS 中的伪元素之前是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在以下取自 Twitter Bootstrap 的 CSS 中,&符号(&) 字符是什么意思?

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

.clearfix {
  *zoom: 1;
  &:before,
  &:after {
    display: table;
    content: "";
  }
  &:after {
    clear: both;
  }
}

推荐答案

那是 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.

这篇关于“&"是什么意思?CSS 中的伪元素之前是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆