简体   繁体   English

CSS 选择器:ID 或 class 在父级但对子级的规则

[英]CSS selector: ID or class in parent but rule for child

I know how to set a CSS-rule für all elements of a type, all elements of a ID and all elements of a type and a ID.我知道如何为一个类型的所有元素、一个 ID 的所有元素以及一个类型和一个 ID 的所有元素设置 CSS 规则。 But I do not know how to do that if only the parent does have a class or ID.但我不知道如果只有父母确实有 class 或 ID 该怎么做。

I want to set the class in the table but I want to define the CSS-rule for the tables element.我想在表格中设置 class 但我想为表格元素定义 CSS 规则。

Eg Every TH inside a TABLE of class "ABC" should have red textcolor.例如,class "ABC" 的表中的每个 TH 都应该有红色的文本颜色。

<table class="ABC">
<tr>
<th>should be red</th>
<td>should be black</td>
</tr>
</table>

<table>
<tr>
<th>should be black</th>
<td>should be black</td>
</tr>
</table>

How do do this selector?这个选择器是怎么做的?

the descendant selector is simply a space.后代选择器只是一个空格。

table th {} select every th that is a child of table . table th table th {} select 每一个是table的孩子。

table.ABC th select every th that is a child of table with class ABC . table.ABC th select 每一个是th ABC的表的孩子。

table.ABC th {
  color: red;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM