Menu
Coddy logo textTech

Zebra Table Rows

Part of the CSS Mastery section of Coddy's HTML journey — lesson 40 of 43.

challenge icon

Challenge

Easy

A 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. 

  1. 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