Home > Article > Web Front-end > 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; }
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>
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!