<分区>
<分区>
<!DOCTYPE html>
<html>
<head>
<title>test</title>
<style>
table > tr > th {
color: red;
}
</style>
</head>
<body>
<table>
<tr>
<th>a</th>
<th>b</th>
</tr>
</table>
</body>
</html>
我只是不明白为什么单元格中的文本不是红色的。你能告诉我我缺少什么吗。
最佳答案
尝试 table tr th
而不是 table > tr > th
因为 tbody
元素作为父元素添加到 tr
由浏览器和自 direct child selector >
被使用,它不会为 th
table tr th {
color: red;
}
<table>
<tr>
<th>a</th>
<th>b</th>
</tr>
</table>
关于html - CSS 直接子选择器未选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49210875/