Home > Web Front-end > CSS Tutorial > How Can I Add a Bottom Border to Each Row of a Table Using CSS?

How Can I Add a Bottom Border to Each Row of a Table Using CSS?

Mary-Kate Olsen
Release: 2024-12-12 20:59:11
Original
240 people have browsed it

How Can I Add a Bottom Border to Each Row of a Table Using CSS?

Adding a Border to Table Row Bottom

Question

Adding a border to the bottom of every table row using CSS seems challenging. Direct styling of tr elements or applying CSS rules to tr didn't produce the desired result. Is there a better way to achieve this without inline styling?

Solution

To successfully add a border to the bottom of each table row using CSS, you can use the border-collapse property. By setting this property to collapse in the table CSS rule, the table borders merge together.

table { 
    border-collapse: collapse; 
}
Copy after login

This allows you to then apply a border style using the border-bottom property in the tr CSS rule.

tr {
  border-bottom: 1pt solid black;
}
Copy after login

Example

Consider a 3x3 table:

<table>
  <tr><td>A1</td><td>B1</td><td>C1</td></tr>
  <tr><td>A2</td><td>B2</td><td>C2</td></tr>
  <tr><td>A2</td><td>B2</td><td>C2</td></tr>
</table>
Copy after login

Applying the CSS rules will result in a table with borders only on the bottom of each row:

table {
  border-collapse: collapse;
}

tr {
  border-bottom: 1pt solid black;
}
Copy after login

The above is the detailed content of How Can I Add a Bottom Border to Each Row of 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