首页htmlelement_relationHTML Element Style - 如何填充nth-child

HTML Element Style - 如何填充nth-child

我们想知道如何填充nth-child。

<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
table tr:nth-child(even) td {
  background-color: yellow;
}

table tr:nth-child(2n+1) td {
  padding-left: 10px;
}

table tr:nth-child(3n+2) td {
  color: blue;
}
</style>
</head>
<body>
  <table border="1">
    <tr>
      <td>row 1, cell 1</td>
      <td>row 1, cell 2</td>
    </tr>
    <tr>
      <td>row 2, cell 1</td>
      <td>row 2, cell 2</td>
    </tr>
    <tr>
      <td>row 3, cell 1</td>
      <td>row 3, cell 2</td>
    </tr>
    <tr>
      <td>row 5, cell 1</td>
      <td>row 5, cell 2</td>
    </tr>
    <tr>
      <td>row 6, cell 1</td>
      <td>row 6, cell 2</td>
    </tr>
    <tr>
      <td>row 7, cell 1</td>
      <td>row 7, cell 2</td>
    </tr>
    <tr>
      <td>row 8, cell 1</td>
      <td>row 8, cell 2</td>
    </tr>
  </table>
</body>
</html>