Zebra Table Rows
Part of the CSS Mastery section of Coddy's HTML journey. Lesson 40 of 43.
Challenge
EasyA table is already given to you. Your task is to use structural pseudo-classes to style every second row with a different background color to create a zebra-striped table effect.
- Use the
:nth-child()pseudo-class to color every second row with a light gray background (#f2f2f2).
Try it yourself
<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>
All lessons in CSS Mastery
1Selector Mastery – Combination
IntroductionDescendant SelectorChild SelectorAdjacent Sibling SelectorGeneral Sibling SelectorRecap Challenge3Structural pseudo-classes
Structural pseudo-classesTargeting the First ChildTargeting the Last ChildPattern Power: Using nth-childRecap Challenge6Landing Page
Style the Header SectionStyle the buttonSection Layout Card Layout Add Finishing Touches9Final Challenges
Highlight Active MenuZebra Table RowsButton Hover EffectGrid Card LayoutBlurred Hero ImagePractice on your own: Web playground