CSS规则仅当元素有BOTH类时才应用 [英] CSS rule to apply only if element has BOTH classes

查看:118
本文介绍了CSS规则仅当元素有BOTH类时才应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我们有这个标记:

<div class="abc"> ... </div>
<div class="xyz"> ... </div>
<div class="abc xyz" style="width: 100px"> ... </div>

是否有方法只选择< div> 其中有BOTH abc xyz 类(最后一个),并覆盖其内联宽度,有效宽度为200像素?

Is there a way to select only the <div> which has BOTH abc and xyz classes (the last one) AND override its inline width to make the effective width be 200px?

这样的东西:

[selector] {
  width: 200px !important;
}


推荐答案

div.abc.xyz {
    /* rules go here */
}


$ b b

...或简单:

... or simply:

.abc.xyz {
    /* rules go here */
}

这篇关于CSS规则仅当元素有BOTH类时才应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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