如何在表格中添加水平线条

时间:2017-08-03 10:37:42

标签: html css html-table border

我希望两个记录和一些额外的底部填充之间有两个水平来添加符号

修改/更新

我正在编写我想要的内容,如下所示

table {
  border: 1px solid black;
  padding: 0em 2em;
}

tr {
  border: 1px solid black;
  padding: 0em 2em;
}

tr:nth-child(3) {
  margin: 0px;
  padding: 0px;
}

tr:nth-child(7) {
  background-color: red
}

td:nth-child(21) {
  border-bottom: 1px solid blue;
}
<table>
  <tr>
    <th colspan="2">Old_records</th>
    <td>32</td>
  </tr>
  
  <tr>
    <th>Records_fetched</th>
    <td colspan="2">100</td>
  </tr>
  
  <tr>
    <td colspan="3"> -----------------------------</td>
  </tr>
  
  <tr>
    <th>Sum </th>
    <td colspan="2">132</td>
  </tr>

  <tr>
    <th>New_records</th>
    <td></td>
    <td>80</td>
  </tr>
  
  <tr>
    <td colspan="3"> -----------------------------</td>
  </tr>

  <tr>
    <th>Differnce </th>
    <td colspan="2">52</td>
  </tr>
</table>

我仍然需要添加符号,我更好的方法是添加边框而不是此行<tr><td colspan="3"> -----------------------------</td></tr>

有人可以建议我如何正确地做到这一点吗?

6 个答案:

答案 0 :(得分:2)

tr中添加边框,并为表格应用border-collapse:collapse

table { 
  border: 1px solid black;
  padding:0em 2em;
  border-collapse: collapse;
}
tr {
  border-bottom: 1px solid black;
}
td {
  padding: 2em;
}
<table>
  <tr>
    <th>Old_records</th>
    <td> 32 </td>
  </tr>
  <tr>
    <th>Records_fetched</th>
    <td>100</td>
  </tr>
  <tr>
    <th>NEw_records</th>
    <td>80</td>
  </tr>
</table>

答案 1 :(得分:0)

table {
  border: 1px solid black;
  padding: 0em 2em;
}

tr {
  border: 1px solid black;
  padding: 0em 2em;
}

tr:nth-child(3) {
  margin: 0px;
  padding: 0px;
}

tr:nth-child(even) > th,
tr:nth-child(even) > td {
  padding-bottom: 0.75em;
  border-bottom: 1px dashed #222;
}

tr:nth-child(odd) > th,
tr:nth-child(odd) > td {
  padding-top: 0.75em;
}
<table>
  <tr>
    <th colspan="2">Old_records</th>
    <td>32</td>
  </tr>
  
  <tr>
    <th>Records_fetched</th>
    <td colspan="2">100</td>
  </tr>
  
  <tr>
    <th>Sum </th>
    <td colspan="2">132</td>
  </tr>

  <tr>
    <th>New_records</th>
    <td></td>
    <td>80</td>
  </tr>

  <tr>
    <th>Differnce </th>
    <td colspan="2">52</td>
  </tr>
</table>

答案 2 :(得分:0)

尝试以下代码

<style>
table {
    border-collapse: collapse;
}

table, td, th {
    border: 1px solid black;
}
</style>
<table>
  <tr>
    <th>Old_records</th>
    <td> 32 </td>
  </tr>
  <tr>
    <th>Records_fetched</th>
    <td>100</td>
  </tr>
  <tr>
    <th>NEw_records</th>
    <td>80</td>
  </tr>
</table>

答案 3 :(得分:0)

要插入空行,您可以写:

<tr>
  <td colspan="2">&nbsp;</td>
</tr>

对于额外的填充,您需要的地方 - 只需添加class="extra-padding-bottom"属性即可 并添加适当的CSS代码:

.extra-bottom-padding {
    padding-bottom: 100px;
}

例如<td class="extra-padding-bottom">

答案 4 :(得分:0)

对我有用的解决方案是在列级别定义css属性,并将colspan定义为表中的列数

HTML-

<tr class="border_bottom">
    <td colspan="6"></td>
</tr>

CSS-

tr.border_bottom td {
    border-bottom: 1px solid #cccccc;
    color: #707070;
}

table {
    border-collapse: collapse;
}

答案 5 :(得分:0)

            <tr>
                <td><hr> </td> 
                <td><hr> </td>
            </tr>

我试过了,成功了