Nth Child Pattern

Nth Child Pattern

Hard CSS CSS Foundations 24 views
Explanation Complexity

Problem Statement

Color every even row in a simple table using :nth-child.

Input Format

No input.

Output Format

Print the HTML+CSS code in one block.

Constraints

Use :nth-child(even) on tr.

Input / Output Format

Input Format
No input.
Output Format
Print the HTML+CSS code in one block.
Constraints
Use :nth-child(even) on tr.

Examples

Input:
Output:
(HTML+CSS code)

Example Solution (Public)

CSS
<!doctype html>
<html lang='en'>
<head>
  <meta charset='utf-8'>
  <meta name='viewport' content='width=device-width, initial-scale=1'>
  <title>meetcode</title>
  <style>
    table { border-collapse: collapse; width: 100%; max-width: 520px; }
    th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
    tbody tr:nth-child(even) { background: #f6f8fa; }
  </style>
</head>
<body>
  <table>
    <thead>
      <tr><th>Topic</th><th>Level</th></tr>
    </thead>
    <tbody>
      <tr><td>HTML</td><td>Easy</td></tr>
      <tr><td>CSS</td><td>Medium</td></tr>
      <tr><td>JavaScript</td><td>Hard</td></tr>
      <tr><td>Python</td><td>Medium</td></tr>
    </tbody>
  </table>
</body>
</html>

Official Solution Code

<!doctype html>
<html lang='en'>
<head>
  <meta charset='utf-8'>
  <meta name='viewport' content='width=device-width, initial-scale=1'>
  <title>meetcode</title>
  <style>
    table { border-collapse: collapse; width: 100%; max-width: 520px; }
    th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
    tbody tr:nth-child(even) { background: #f6f8fa; }
  </style>
</head>
<body>
  <table>
    <thead>
      <tr><th>Topic</th><th>Level</th></tr>
    </thead>
    <tbody>
      <tr><td>HTML</td><td>Easy</td></tr>
      <tr><td>CSS</td><td>Medium</td></tr>
      <tr><td>JavaScript</td><td>Hard</td></tr>
      <tr><td>Python</td><td>Medium</td></tr>
    </tbody>
  </table>
</body>
</html>
Please login to submit solutions.
Editor
Output

                                        
Please login to submit solutions.