How to Add Space Between Rows in a Table Using CSS?

Susan Sarandon
Release: 2024-11-11 14:37:02
Original
138 people have browsed it

How to Add Space Between Rows in a Table Using CSS?

How to Create Space Between Rows in a Table

Question:

Is it possible to add space between rows in a table using CSS? The following code is not producing the desired result:

tr.classname {
  border-spacing: 5em;
}
Copy after login

Answer:

To create space between rows in a table, you need to use padding on the td elements. You can use the following CSS code:

tr.spaceUnder > td {
  padding-bottom: 1em;
}
Copy after login

In this code, the tr.spaceUnder > td selector applies the padding only to td elements that are direct children of tr elements with the class spaceUnder. This allows you to use nested tables without affecting the spacing between rows.

Example:

<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

Output:

A B
C D
E F

The above is the detailed content of How to Add Space Between Rows in a Table Using 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