You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何消除表格border-bottom间隙及移除最后一行边框?

表格边框问题解决方法

核心问题解决

  1. 消除列边框间隙:给表格添加border-collapse: collapse属性,让单元格边框合并,彻底解决列间间隙问题。
  2. 移除最后一行边框:针对no-border类的行,给其内部单元格设置border-bottom: none,覆盖全局td的边框样式。

修改后的代码

CSS

table {
  width: 100%;
  border-collapse: collapse; /* 合并单元格边框,消除间隙 */
}

.amount {
  font-weight: 700;
  color: hsl(14, 45%, 36%);
}

td {
  border-bottom: solid hsl(30, 18%, 87%) 1px;
}

/* 精准移除最后一行的底部边框 */
.no-border td {
  border-bottom: none;
}

HTML

<table class="nutrition-table">
  <tr>
    <td class="table-row">Calories</td>
    <td class="table-row amount">277kcal</td>
  </tr>
  <tr>
    <td class="table-row">Carbs</td>
    <td class="table-row amount">0g</td>
  </tr>
  <tr>
    <td class="table-row">Protein</td>
    <td class="table-row amount">20g</td>
  </tr>
  <tr class="no-border">
    <td class="table-row">Fat</td>
    <td class="table-row amount">22g</td>
  </tr>
</table>

关键说明

  • border-collapse: collapse会让表格相邻单元格的边框合并为一条连续线条,从根源消除列边框间隙。
  • 之前设置白色、透明边框无效,是因为全局td样式优先级更高,通过.no-border td的精准选择器可以直接覆盖原有样式,确保最后一行无底部边框。

内容的提问来源于stack exchange,提问作者Mina Hopgood

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 15:57:43