使用 CSS 的 HTML 表格列样式

标签 html css

我有以下 HTML 表格,我需要在最后一列中使用不同的样式:
https://jsfiddle.net/dqa9y1g3/

table {
  border-collapse: collapse;
  border-right: 0px;
  border: 1px solid;
}

td {
  border: 1px solid;
}

thead {
  border: 2px;
}

th.th {
  border: solid;
}

th.th3 {
  border-top: 1px dashed;
  font-weight: normal;
}
<table>
  <thead>
    <tr>
      <th class="th">h1</th>
      <th class="th">h2</th>
      <th class="th3">h3</th>
    </tr>
  </thead>
  <tr>
    <td>r1c1</td>
    <td>r1c2</td>
    <td>r1c3</td>
  </tr>
  <tr>
    <td>r2c1</td>
    <td>r2c2</td>
    <td>r2c3</td>
  </tr>
</table>

正确的做法是什么?
这就是我想要得到的:
Expected result

最佳答案

如果您特别需要定位最后一列,您可以使用它。 您还需要删除表格边框,因为它将绘制在单独的 thtd 边框上。

table {
  border-collapse: collapse;
}

td {
  border: 1px solid;
}

thead {
  border: 2px;
}

th.th {
  border: solid;
}

tr th:last-child,
tr td:last-child {
  border: 1px dashed #000;
  border-right: 0;
}
<table>
  <thead>
    <tr>
      <th class="th">h1</th>
      <th class="th">h2</th>
      <th class="th">h3</th>
    </tr>
  </thead>
  <tr>
    <td>r1c1</td>
    <td>r1c2</td>
    <td>r1c3</td>
  </tr>
  <tr>
    <td>r2c1</td>
    <td>r2c2</td>
    <td>r2c3</td>
  </tr>
</table>

关于使用 CSS 的 HTML 表格列样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72304719/

相关文章:

html - 如何创建多列列表?

css - bootstrap 4 : dropdown, nav-pills 和水平线中的单独链接

javascript - slideDown 到最后突然跳转

html - 在 html 和 css 中调整大小收缩

html - Font-Awesome fa-circle 有两种颜色?

css - 变换比例适用于 Chrome 但不适用于 Firefox

html - Webview ios 7 中的垂直对齐文本

html - 如何更改响应式 iFrame 的高度?

css - 没有导航栏元素的 Bootstrap 导航切换

javascript - HTML 样式表相互干扰