Menu
Coddy logo textTech

Чередование строк таблицы

Часть раздела CSS Mastery путешествия по HTML на Coddy — урок 40 из 43.

challenge icon

Задание

Легко

Таблица уже предоставлена. Ваша задача — использовать структурные псевдоклассы для стилизации каждой второй строки другим цветом фона, чтобы создать эффект зебры (чередующихся строк)

  1. Используйте псевдокласс :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 Mastery