How to Add Space Between Table Rows with CSS?

Mary-Kate Olsen
Release: 2024-11-10 06:30:02
Original
915 people have browsed it

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;
}
Copy after login

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>
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template