Home > Web Front-end > CSS Tutorial > How to Achieve Rounded Table Corners Using Only CSS?

How to Achieve Rounded Table Corners Using Only CSS?

Patricia Arquette
Release: 2024-11-20 02:02:02
Original
400 people have browsed it

How to Achieve Rounded Table Corners Using Only CSS?

Rounded Table Corners with CSS Only

Users seeking to achieve rounded corners on HTML tables with only CSS may encounter difficulties finding solutions that preserve the table's borders. Here's a comprehensive approach that addresses this issue:

CSS Implementation

table {
  border-collapse: separate;
  border: solid black 1px;
  border-radius: 6px;
}

td, th {
  border-left: solid black 1px;
  border-top: solid black 1px;
}

th {
  background-color: blue;
  border-top: none;
}

td:first-child, th:first-child {
  border-left: none;
}
Copy after login

Explanation

Firstly, setting border-collapse: separate allows borders to appear between cells. Then, the border property defines the outer border of the table. The border-radius creates the rounded corners.

Within the cells and headers, border-left and border-top specify the vertical and horizontal borders, respectively. Headers have a blue background to showcase the rounded corners. Additionally, border-top is removed for headers to prevent overlapping with the table's outer border.

Finally, removing the border-left on the first cells and headers eliminates unnecessary vertical borders. This results in rounded corners for all corner cells while preserving the vertical and horizontal borders within the table.

Example Usage

<table>
  <thead>
    <tr>
      <th>Blah</th>
      <th>Fwee</th>
      <th>Spoon</th>
    </tr>
  </thead>
  <tr>
    <td>Blah</td>
    <td>Fwee</td>
    <td>Spoon</td>
  </tr>
  <tr>
    <td>Blah</td>
    <td>Fwee</td>
    <td>Spoon</td>
  </tr>
</table>
Copy after login

The above is the detailed content of How to Achieve Rounded Table Corners Using Only 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