表格斑马纹行
本课属于 Coddy HTML 学习旅程的“精通 CSS”单元。第 40 课,共 43 课。
挑战
简单已经为你提供了一个表格。你的任务是使用结构伪类为每隔一行设置不同的背景颜色,创建斑马纹表格效果。
- 使用
:nth-child()伪类,将每隔一行的背景颜色设为浅灰色(#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>
精通 CSS中的所有课
自己练习: Web 在线编辑器