css里的&符号是代表什么意思呢?

        .el-row {
                margin-bottom: 20px;
                &:last-child {
                        margin-bottom: 0;
                }
        }
阅读 75.6k
10 个回答

这是sass的语法,代表上一级选择器,实际编译成css就是 .el-row:last-child{}

跟this的意思一样

.bordered {
  &.float {
    float: left; 
  }
  .top {
    margin: 5px; 
  }
}

等同于:

.bordered.float {
  float: left; 
}
.bordered .top {
  margin: 5px;
}

.bordered.float 是串联选择器,作用在同一标签上
.bordered .top 是后代选择器,作用在不同标签上

sass语法,等同于
.el-row {
  margin-bottom: 20px;
}
.el-row:last-child {
  margin-bottom: 0;
}

scss和less里的语法,表示当前选择对象

不能算是css里的吧。

& 表示嵌套的上一级。

比如你的代码中,& 表示 .el-row 可以看做是嵌套里面的一个变量,值是 代表上一级选择器

sass、less语法,等同于
.el-row {
margin-bottom: 20px;
}
.el-row:last-child {
margin-bottom: 0;
}

scss语法,表示上一级

表示此元素的伪类

新手上路,请多包涵

less中的连字符

推荐问题