将伪类样式应用于所有前面的类

时间:2016-01-29 04:21:19

标签: html css css3

所以,如果我正在应用如下的样式:

.class1, .class2, .class3 {}

然后我可以在同一行中应用这些类的特定伪样式而不重复所有类名的方法是什么?

1 个答案:

答案 0 :(得分:1)

我有时使用手写笔,手写笔是一个CSS预编译器。对于你的情况,我将举例说明它在手写笔中的外观。

.class1 , .class2 , .class3
  color red
  background-color blue 
     &:hover 
          color blue
          background-color red

上面的代码会自动将代码预编译到.css文件中,就像这样

.class1,
.class2,
.class3 {
  color: #f00;
  background-color: #00f;
}
.class1:hover,
.class2:hover,
.class3:hover {
  color: #00f;
  background-color: #f00;
}

如果你跑SASS / LESS,它看起来几乎一样,但有范围。