【发布时间】:2018-07-14 11:33:32
【问题描述】:
问题
当浏览器默认没有指定text-align: center; 时,为什么th 元素的文本居中?
系统设置
- MacBook Pro,2014 年中
- OS X v 10.10.2
- Google Chrome v 40.0.2214.94(64 位)
- 截至发帖时所有软件都是最新的
示例代码
<!-- no external or internal CSS applied.
browser default styles only. -->
<table width="500" border="1"> <!-- attributes for debugging only. never use these attributes in real code (use CSS instead). -->
<tr><th> table heading </th><th> centered text </th></tr>
<tr><td> table data </td><td> left-aligned text </td></tr>
</table>
屏幕截图
HTML 渲染:
第一个 th 元素上的开发工具:
我在这里看不到text-align: center;,但很明显th 中的文本是居中对齐的。这是 Chrome 的错误吗?
相关问题
更新
从 Chrome v67 开始,th 现在默认具有指定的 text-align: -internal-center;。
【问题讨论】:
-
我猜
<th>默认情况下会以这种方式出现,因为(据我所知)根据 HTML 规范不需要它是其他任何东西。 编辑: 事实上,this W3 page 建议<th>的默认样式应该是{ font-weight: bolder; text-align: center } -
我知道HTML recommends
thelements appear centered and bold。我不知道的是 Google Chrome 是如何在 CSS 中没有text-align: center;的情况下呈现的。但是我确实看到了font-weight: bold;,如我的屏幕截图所示。
标签: html css google-chrome