I try to draw border-radius on certain rows.
The structure is as follow:
<tr>row with border-top-radius</tr>
<tr>normal row with some tds</tr>
<tr>normal row with some tds</tr>
<tr>normal row with some tds</tr>
<tr>row with border-bottom-radius</tr>
This block repeated with arbitrary number of <tr>normal row with some tds</tr>
The table should be border-collapse: collapse;
I try to play with <div>
but border lines are discontinued
- left border; Cell 1 and 5
- right border; Cell 4 and 8
How to fix this?
table {
border-collapse: collapse;
}
td {
border: 2px solid black;
padding: 10px;
height: 50px;
width: 100px;
}
.footer > td:first-child {
border-left: none;
border-bottom: none;
padding: 0;
}
.footer > td:last-child {
border-right: none;
border-bottom: none;
padding: 0;
}
.footer > td:first-child > div {
height: 100%;
width: 100%;
border-left: 2px solid black;
border-bottom: 2px solid black;
border-bottom-left-radius: 10px;
}
.footer > td:last-child > div {
height: 100%;
width: 100%;
border-right: 2px solid black;
border-bottom: 2px solid black;
border-bottom-right-radius: 10px;
}
<div>
<table>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
<td>Cell 3</td>
<td>Cell 4</td>
</tr>
<tr class="footer">
<td>
<div>Cell 5</div>
</td>
<td>Cell 6</td>
<td>Cell 7</td>
<td>
<div>Cell 8</div>
</td>
</tr>
</table>
</div>
EDIT
By "This block repeated with arbitrary number of <tr>normal row with some tds</tr>
", I mean there are multiple blocks like that block. The difference between each block is the number of normal <tr>
inside that block.
Something like this
table {
border-collapse: collapse;
}
th {
border: 2px solid black;
}
td {
border: 2px solid black;
padding: 5px;
height: 30px;
width: 100px;
}
.spacer > td {
border: none;
height: 10px;
}
.header > td:first-child {
border-left: none;
border-top: none;
padding: 0;
}
.header > td:last-child {
border-right: none;
border-top: none;
padding: 0;
}
.header > td:first-child > div {
height: 100%;
width: 100%;
border-left: 2px solid black;
border-top: 2px solid black;
border-top-left-radius: 10px;
}
.header > td:last-child > div {
height: 100%;
width: 100%;
border-right: 2px solid black;
border-top: 2px solid black;
border-top-right-radius: 10px;
}
.footer > td:first-child {
border-left: none;
border-bottom: none;
padding: 0;
}
.footer > td:last-child {
border-right: none;
border-bottom: none;
padding: 0;
}
.footer > td:first-child > div {
height: 100%;
width: 100%;
border-left: 2px solid black;
border-bottom: 2px solid black;
border-bottom-left-radius: 10px;
}
.footer > td:last-child > div {
height: 100%;
width: 100%;
border-right: 2px solid black;
border-bottom: 2px solid black;
border-bottom-right-radius: 10px;
}
<div>
<table>
<thead>
<th>Header</th>
<th>Header</th>
<th>Header</th>
<th>Header</th>
</thead>
<tbody>
<tr class="spacer">
<td colspan="4"></td>
</tr>
<tr class="header">
<td>
<div>Cell</div>
</td>
<td>Cell</td>
<td>Cell</td>
<td>
<div>Cell</div>
</td>
</tr>
<tr>
<td>Cell</td>
<td>Cell</td>
<td>Cell</td>
<td>Cell</td>
</tr>
<tr class="footer">
<td>
<div>Cell</div>
</td>
<td>Cell</td>
<td>Cell</td>
<td>
<div>Cell</div>
</td>
</tr>
<tr class="spacer">
<td colspan="4"></td>
</tr>
<tr class="header">
<td>
<div>Cell</div>
</td>
<td>Cell</td>
<td>Cell</td>
<td>
<div>Cell</div>
</td>
</tr>
<tr>
<td>Cell</td>
<td>Cell</td>
<td>Cell</td>
<td>Cell</td>
</tr>
<tr>
<td>Cell</td>
<td>Cell</td>
<td>Cell</td>
<td>Cell</td>
</tr>
<tr class="footer">
<td>
<div>Cell</div>
</td>
<td>Cell</td>
<td>Cell</td>
<td>
<div>Cell</div>
</td>
</tr>
</tbody>
</table>
</div>
2
Answers
Just add border outer div of table, and give inside borders through td as below. It will give consistent borders.
As others have mentioned, you will need to wrap your
<table>
inside of a<div>
to get rounded corners.Once you set the
border-collapse
property of the<table>
tocollapse
, you lose the ability to set theborder-radius
.Here is a modern approach that also utilizes semantic HTML i.e.
<thead>
,<tbody>
and<tfoot>
: