的 height 不生效是因为其本身不参与常规盒模型计算,chrome 完全忽略、firefox 表现不一致;真正决定行高的,是 或 的 height、line-height、padding 和内容撑开效果。

直接给 <th> 设 <code>height + line-height + vertical-align: middle 是最稳的方案,<tr> 上的 <code>height 属性在 Chrome 里基本被忽略,Firefox 表现也不一致。
为什么 <tr> 的 <code>height 不生效
浏览器对 <tr> 元素的 <code>height 属性支持极弱:Chrome 完全无视,Firefox 可能部分响应但不可靠。真正起作用的是单元格(<th> 或 <code><td>)自身的盒模型高度和内容排布逻辑。
<ul><li><code><tr> 本身不是“块级容器”,它不参与常规盒模型计算
<li>行高最终由所有 <code><th> 中最大的 <code>height、padding、字体大小和 line-height 共同决定
<th> 内容换行或含图片,会立刻撑开整行——此时仅设 <code>height 会被覆盖
<th> 高度控制的关键 CSS 组合
<p>单行表头推荐用固定像素值锁定视觉高度,并确保文字垂直居中:</p><div class="aritcle_card flexRow artxards">
<div class="artcardd flexRow">
<a class="aritcle_card_img" rel="nofollow" href="/xiazai/skill6712" title="Wechat HTML Publisher"><img
src="https://img.php.cn/upload/skill/000/000/081/179109368394970.jpg" alt="Wechat HTML Publisher" onerror="this.onerror='';this.src='/static/lhimages/moren/morentu.png'" ></a>
<div class="aritcle_card_info flexColumn">
<a rel="nofollow" href="/xiazai/skill6712" title="Wechat HTML Publisher" class="overflowclass">Wechat HTML Publisher</a>
<p class="overflowclass">直接上传HTML富文本到微信公众号草稿箱。支持完整的HTML格式,无需Markdown转换。</p>
</div>
<a rel="nofollow" href="/xiazai/skill6712" title="Wechat HTML Publisher" class="aritcle_card_btn flexRow flexcenter"><b></b><span>下载</span>
</a>
</div>
</div>
<pre class="brush:php;toolbar:false;">th {
height: 48px;
line-height: 48px;
vertical-align: middle;
padding: 0;
box-sizing: border-box;
}</pre>
<ul>
<li>
<code>height 和 line-height 必须相等,否则文字会偏上或偏下
padding: 0 是必须项,否则默认内边距会让实际高度超出设定值box-sizing: border-box 确保 height 包含边框和内边距(虽然这里设了 padding: 0,但留着更安全)display: flex; align-items: center; justify-content: center; 替代 line-height
多行表头或动态内容怎么办
当表头需要显示两行文字(比如“订单编号
(唯一标识)”),或内容来自 CMS/框架渲染时,line-height 失效,必须换策略:
- 用
min-height替代height,允许内容自然撑开但保底高度 - 加
white-space: normal; word-break: break-word;防止长单词挤爆单元格 - 必要时套一层
<div> 在 <code><th> 内,设 <code>display: flex; flex-direction: column; justify-content: center; - 避免用
overflow: hidden截断表头文字——可读性优先于整齐
最容易被忽略的是:表头行高变化后,<tbody> 的 <code><td> 如果没同步设置,会出现上下不对齐;哪怕只调表头,也要检查整张表的 <code>vertical-align 是否统一。










