Warm tip: This article is reproduced from stackoverflow.com, please click
css html html-table

How can I let html table borders merge into each other in css

发布于 2020-03-28 23:14:11

In a current project I have a three-columned table.

<table>
    <tr>
        <th>Datum</th>
        <th>Entschuldigt?</th>
        <th>Vermerkt von</th>
    </tr>
</table>

My current stylesheet for the table looks as following:

th {
    border-bottom: 1px solid black;
}

td + td {
    border-left: 1px solid black;
    border-right: 1px solid black;
}

Now the table looks like this current_table

Now I would like to have those little spaces removed so the column separators and the header separator are solid and not that kind of dashed. Every help is very much appreciated

Questioner
byTreneib
Viewed
15
Omri Attiya 2020-01-31 15:04

You need to use border-collapse: collapse on the table:

th {
  border-bottom: 1px solid black;
}

td+td {
  border-left: 1px solid black;
  border-right: 1px solid black;
}

table {
   border-collapse: collapse;
}
<table>
  <tr>
    <th>Datum</th>
    <th>Entschuldigt?</th>
    <th>Vermerkt von</th>
  </tr>
  <tr>
    <td>item 1</td>
    <td>item 2</td>
    <td>item 3</td>
  </tr>
  <tr>
    <td>item 1</td>
    <td>item 2</td>
    <td>item 3</td>
  </tr>
</table>