css - 在一个复杂选择器中选择两个类
问题描述
给定两个长而复杂的选择器,例如
.question-number td:first-child > span[...]
.question-text td:first-child > span[...]
有没有办法将两者合并,使得长后缀不需要重复?类似的东西(尽管这不是有效的 CSS)
(.question-number | .question-text) td:first-child > span[...]
解决方案
如果您只有这两个包含单词question的类,您可以考虑如下属性选择器:
[class*=question] td:first-child>span {
color: red;
}
<table>
<tr class="anoher-class">
<td><span>some text</span></td>
</tr>
<tr class="question-number">
<td><span>some text</span></td>
</tr>
<tr>
<td><span>some text</span></td>
</tr>
<tr class="question-text">
<td><span>some text</span></td>
</tr>
</table>
推荐阅读
- android - 在android中的viewmodel中扭曲MVP演示者?
- postgresql - 更改 solr 存储日期和时间的方式
- c# - 在 asyc 方法中抛出新异常
- google-chrome-extension - Chrome 扩展开发试图使字体加粗
- c++ - 警告 C26454:算术溢出:“-”操作在编译时产生负的无符号结果 (io.5)
- sql-server - 带有过滤器的 SQL Server 分组依据
- javascript - 如何从 JSON.stringify 中正确提取数据
- python - 将列中所有时间条目的时间格式从小时更改为上午/下午
- c# - C# GetWindowModuleFileName 和 GetWindowText 给出不同句柄的结果
- c# - Xamarin Forms:没有名称='getDrawable'签名='(I)Landroid/graphics/drawable/Drawable;'的方法 在 Landroid/content/Context 类中;