html - CSS 直接子选择器未选择

标签 html css

<分区>

<!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/

上一篇:javascript - 在进入网站的成人部分之前需要警报或弹出窗口或其他内容

下一篇:html - 没有悬停效果?

相关文章:

javascript - 使用 IntersectionObserver 实现粘性 header

javascript函数只能工作一次

javascript - 使用jquery从表中获取订单总值(value)

javascript - 我怎样才能按原样打印页面

c# - Go to Href <a href =""> From .Cs 文件函数

html - Safari 错误 - 输入 :checked with two labels controlling it

Javascript函数调整窗口高度和宽度

html - 在图像上放置文本

javascript - 如何正确清除 "setTimeout"JavaScript

javascript - jQuery FadeIn 如何知道使用的显示模式?