角の丸いテーブルを表示するには

目次

thead, tbody, tfoot を使用しない場合

角の丸いテーブルの実現方法を下記に示します。

CSS
.my-round-table { border-spacing: 0; }
.my-round-table > * > tr > th { background-color: #ddf; }
.my-round-table > * > tr > td { text-align: center; }
.my-round-table > * > tr > *  { width: 6rem; border-right: 1px solid #999; border-bottom: 1px solid #999; }
.my-round-table > * > tr:first-child > *:first-child { border-top-left-radius:     .5rem; }
.my-round-table > * > tr:first-child > *:last-child  { border-top-right-radius:    .5rem; }
.my-round-table > * > tr:last-child  > *:first-child { border-bottom-left-radius:  .5rem; }
.my-round-table > * > tr:last-child  > *:last-child  { border-bottom-right-radius: .5rem; }
.my-round-table > * > tr:first-child > *  { border-top:  1px solid #999; }
.my-round-table > * > tr > *:first-child  { border-left: 1px solid #999; }
HTML
<table class="my-round-table">
  <tr><th></th><th>列A</th><th>列B</th><th>列C</th></tr>
  <tr><th>行1</th><td>A1</td><td>B1</td><td>C1</td></tr>
  <tr><th>行2</th><td>A2</td><td>B2</td><td>C2</td></tr>
  <tr><th>行3</th><td>A3</td><td>B3</td><td>C3</td></tr>
</table>
表示
列A列B列C
行1A1B1C1
行2A2B2C2
行3A3B3C3

thead, tbody, tfoot を使用する場合

thead, tbody, tfoot を使用する場合、下記の様に thead, tbody, tfoot それぞれの角が丸まってしまい、thead, tbody, tfoot 間の枠線も太くなってしまいます。

表示
列A列B列C
行1A1B1C1
行2A2B2C2
行3A3B3C3
行4A4B4C4

これを防ぐには上記の CSS を下記の様に改善します。

CSS
.my-round-table { border-spacing: 0; }
.my-round-table > * > tr > th { background-color: #ddf; }
.my-round-table > * > tr > td { text-align: center; }
.my-round-table > * > tr > *  { width: 6rem; border-right: 1px solid #999; border-bottom: 1px solid #999; }
.my-round-table:has(thead)       > thead > tr:first-child > *:first-child,
.my-round-table:not(:has(thead)) > tbody > tr:first-child > *:first-child { border-top-left-radius:     .5rem; }
.my-round-table:has(thead)       > thead > tr:first-child > *:last-child,
.my-round-table:not(:has(thead)) > tbody > tr:first-child > *:last-child  { border-top-right-radius:    .5rem; }
.my-round-table:has(tfoot)       > tfoot > tr:last-child  > *:first-child,
.my-round-table:not(:has(tfoot)) > tbody > tr:last-child  > *:first-child { border-bottom-left-radius:  .5rem; }
.my-round-table:has(tfoot)       > tfoot > tr:last-child  > *:last-child,
.my-round-table:not(:has(tfoot)) > tbody > tr:last-child  > *:last-child  { border-bottom-right-radius: .5rem; }
.my-round-table:has(thead)       > thead > tr:first-child > *,
.my-round-table:not(:has(thead)) > tbody > tr:first-child > *  { border-top:  1px solid #999; }
.my-round-table > * > tr > *:first-child  { border-left: 1px solid #999; }
表示
列A列B列C
行1A1B1C1
行2A2B2C2
行3A3B3C3
行4A4B4C4