テーブルのゼブラストライプ
CoddyのHTMLジャーニー「CSS Mastery」セクションの一部 — レッスン 40/43。
チャレンジ
簡単テーブルはあらかじめ用意されています。あなたのタスクは、構造的疑似クラスを使用して、1行おきに異なる背景色を設定し、ゼブラストライプのテーブル効果を作成することです。
:nth-child()疑似クラスを使用して、1行おき(偶数行)を薄いグレーの背景色(#f2f2f2)で色付けしてください。
自分で試してみよう
<html>
<head>
<title>Zebra Table Rows</title>
<style>
.destinations {
width: 100%;
border-collapse: collapse;
font-family: sans-serif;
}
.destinations th, .destinations td {
padding: 12px;
text-align: left;
border-bottom: 1px solid #ccc;
}
/* Add your styles here */
</style>
</head>
<body>
<table class="destinations">
<tr>
<th>Destination</th>
<th>Country</th>
<th>Best Season</th>
</tr>
<tr>
<td>Kyoto</td>
<td>Japan</td>
<td>Spring</td>
</tr>
<tr>
<td>Reykjavik</td>
<td>Iceland</td>
<td>Winter</td>
</tr>
<tr>
<td>Barcelona</td>
<td>Spain</td>
<td>Summer</td>
</tr>
<tr>
<td>Cape Town</td>
<td>South Africa</td>
<td>Autumn</td>
</tr>
</table>
</body>
</html>