3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

背景色がある角丸tableをつくる

Last updated at Posted at 2019-02-19

コードと記事の背景

こんな感じの角丸のテーブルを作ります。
角丸テーブルの作り方はすぐ見つかったけど、背景色ありの角丸テーブルの作り方が調べてすぐ出なかったので備忘録までに。

See the Pen 角丸table by guchiparasol (@guchiparasol) on CodePen.

解説

border-radiusでtableを角丸にする。


.table-radius {
  border: none;
  border-radius: 5px;
  border-spacing: 0;
  border-collapse: separate;
}

罫線と背景色を設定する。

.table-radius tr th,
.table-radius tr td {
	border: none;
	border-bottom: 1px solid #ccc;
	border-right: 1px solid #ccc;
}

.table-radius tr:nth-child(odd){
  background: #ddd;  
}

.table-radius tr th{
  background: #333; 
  color:#fff;
}

.table-radius tr td:first-child {
  border-left: none;
}

.table-radius tr td:last-child {
  border-right: none;
}

背景色を設定した場合、角丸を無視して真四角に塗られてしまうので、四隅のth・tdタグに角丸を設定する。

.table-radius tr th:first-child {
  border-radius: 5px 0 0 0;
}

.table-radius tr th:last-child {
  border-right: none;
  border-radius: 0 5px 0 0;
}

.table-radius tr:last-child td:first-child{
  border-top: none;
  border-radius: 0 0 0 5px;
}
.table-radius tr:last-child td:last-child {
  border-bottom: none;
  border-radius: 0 0 5px 0;
}
3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?