html - CSS 表格 - 添加边距列和行 border-bottom

标签 html css html-table css-tables

我有一个 HTML 表格元素,我想在列之间添加边距,所以我使用了这些 css 属性:

table {
 border-collapse: separate;
 border-spacing: 36px 0px;
}

现在我想将 border-bottom 添加到整行,包括标题和正文中的每个 tr,但边框没有出现。 我用过:

tr {
 border-bottom: 1px solid blue;
}

它仅在我使用时出现:

table {
 border-collapse: collapse;
}

但是我不会在列之间留边距。

我添加了我的 DEMO here .

最佳答案

您可以使用 :after 伪类来设置样式,如下所示:

body {
  background: #eee;
}

.mytable{
  border-collapse: separate;
  background-color: white;
  border-spacing: 36px 0px;
  position: relative;
  overflow: hidden;
}

.mytable td,
.mytable th {
  border-left: 1px solid black;
  border-right: 1px solid black;
}

.mytable th:after,
.mytable td:after {
  position: absolute;
  background: blue;
  margin-top: 18px;
  content: '';
  height: 1px;
  right: 0;
  left: 0;
}
<table class="mytable">
  <thead>
    <tr>
      <th>aaa</th>
      <th>bbb</th>
      <th>ccc</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>ddd</td>
      <td>eee</td>
      <td>fff</td>
    </tr>
    <tr>
      <td>ggg</td>
      <td>hhh</td>
      <td>iii</td>
    </tr>
  </tbody>
</table>

关于html - CSS 表格 - 添加边距列和行 border-bottom,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40604231/

相关文章:

css - 改变类风格

Css - 输入尺寸不同的分辨率和屏幕尺寸

css - 如何使用 CSS 将元素样式定义为位于另一个元素之上?为什么在我的情况下 z-index 无效?

html - 如何将 "height:auto"应用于 HTML 表格列? (或类似的东西)

html - CSS 位置 : sticky not working with display: table-row-group

html - Bootstrap 5 - 为不同的断点显示不同的响应图像

html - float DIV 适合另一个 DIV

html - 单元格表格中的翻转图像覆盖先前的单元格图像 - 表格中的重复图像

javascript - 为什么我的交通灯代码不起作用?

javascript - 样式表文件内 JS 中的 for 循环出错