CSS 选择器“(A 或 B)和 C"? [英] CSS Selector "(A or B) and C"?

查看:17
本文介绍了CSS 选择器“(A 或 B)和 C"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这应该很简单,但我无法找到它的搜索词.
假设我有这个:

This should be simple, but I'm having trouble finding the search terms for it.
Let's say I have this:

<div class="a c">Foo</div>
<div class="b c">Bar</div>

在 CSS 中,如何创建一个选择器来匹配匹配(.a 或 .b)和 .c"的内容?

In CSS, how can I create a selector that matches something that matches "(.a or .b) and .c"?

我知道我可以这样做:

.a.c,.b.c {
  /* CSS stuff */
}

但是,假设我要经常做这种逻辑,有多种逻辑组合,有没有更好的语法?

But, assuming I'm going to have to do this sort of logic a lot, with a variety of logical combinations, is there a better syntax?

推荐答案

有更好的语法吗?

is there a better syntax?

没有.CSS 的 or 运算符 (,) 不允许分组.它本质上是选择器中优先级最低的逻辑运算符,因此您必须使用 .a.c,.b.c.

No. CSS' or operator (,) does not permit groupings. It's essentially the lowest-precedence logical operator in selectors, so you must use .a.c,.b.c.

这篇关于CSS 选择器“(A 或 B)和 C"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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