选择具有相同属性的多个类 [英] Select multiple classes with same property

查看:242
本文介绍了选择具有相同属性的多个类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个这样的类具有相同的属性:

  .class1> div {
background-color:red;
}

我尝试用以下方法减少CSS代码:

  .class1,.class2,.class3> div {
background-color:red;
}

但它不能正常工作,它只需要最后一个类有没有办法做到这一点?

div class =h2_lin>解决方案

如果你想为每个类选择子div,你需要用每个类的选择器来指定它:



CSS

  .class1> div,.class2> div,.class3> div {
background-color:red!important;
}

单一选择器(错误)



每个类别的选择器(右)


I have multiple classes like this with same property:

.class1 > div{
  background-color: red;
}

I try to reduce the CSS code with:

.class1, .class2, .class3 > div{
  background-color: red;
}

But it doesn't work properly, it only takes the last class in this case .class3.

Is there a way to properly do this?

解决方案

If you want the child div selected for each of the classes, you'll need to specify it with the selector for each class like so:

CSS

.class1 > div, .class2 > div, .class3 > div {
  background-color: red !important;
}

Single Selector (Wrong)

Selector For Each Class (Right)

这篇关于选择具有相同属性的多个类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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