Home >Web Front-end >CSS Tutorial >How to Add Space Between Table Rows with CSS?

How to Add Space Between Table Rows with CSS?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-11-10 06:30:02946browse

How to Add Space Between Table Rows with CSS?

How to Create Space Between Table Rows

Separating table rows can be achieved using the padding property on td elements. To provide the desired spacing, employ the following CSS:

/* Apply padding to td elements that are direct children of tr elements with class spaceUnder. */
tr.spaceUnder > td {
  padding-bottom: 1em;
}

This code ensures that padding is only applied to td elements that are directly descended from tr elements with the class spaceUnder. This allows for nested tables.

To demonstrate, consider the following table:

<table>
  <tbody>
    <tr>
      <td>A</td>
      <td>B</td>
    </tr>
    <tr class="spaceUnder">
      <td>C</td>
      <td>D</td>
    </tr>
    <tr>
      <td>E</td>
      <td>F</td>
    </tr>
  </tbody>
</table>

With the CSS provided, there will be a space underneath row CD, while rows AB and EF remain unaffected.

The above is the detailed content of How to Add Space Between Table Rows with CSS?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn