I want to give my first and last <td>
a border-radius
so that my table looks like a rounded table.
First I applied background to my <td>
and then added border-radius
, which works fine I think(background rounded from the corner).
After that when I applied border to my <td>
, I saw a weird thing(See below snippet).
So my question is why border is not rounded as background?
Stack Snippet
table {
width: 100%;
border-collapse: collapse;
table-layout: fixed;
text-align: center;
font: 13px Verdana;
}
table td {
border: 1px solid #000000;
padding: 20px;
background: red;
color: #ffffff;
}
table tbody tr:first-child td:first-child {
border-radius: 20px 0 0 0;
}
table tbody tr:first-child td:last-child {
border-radius: 0 20px 0 0;
}
<table>
<tr>
<td>One</td>
<td>Two</td>
<td>Three</td>
</tr>
</table>
Instead, you can give a border radius to the two lefthand corners of the first TD and the two righthand corners of the last one. You can use first-child and last-child selectors as suggested by theazureshadow, but these may be poorly supported by older versions of IE.
Bonus info: border-radius has no effect on tables with border-collapse: collapse; and border set on td 's. And it doesn't matter if border-radius is set on table, tr or td —it's ignored. Show activity on this post.
The easiest way to add border radius to a table element that accepts border as a property, is doing border radius with overflow: hidden. Show activity on this post. Show activity on this post.
Definition and Usage. The border-radius property defines the radius of the element's corners. Tip: This property allows you to add rounded corners to elements! This property can have from one to four values. Here are the rules:
try border-collapse: inherit;
and make 'border-spacing: 0px;'
table {
width: 100%;
border-collapse: inherit;
table-layout: fixed;
text-align: center;
font: 13px Verdana;
border-radius: 30px;
border-spacing: 0px;
}
table td {
border: 1px solid #000000;
padding: 20px;
background: red;
color: #ffffff;
border-left: none;
}
table td:first-child{
border-left: 1px solid #000000;
}
table tbody tr:first-child td:first-child {
border-radius: 20px 0 0 0;
}
table tbody tr:first-child td:last-child {
border-radius: 0 20px 0 0;
}
<table>
<tr>
<td>One</td>
<td>Two</td>
<td>Three</td>
</tr>
</table>
Please checkout this solution with first row and last row rounded.
HTML
<table>
<tr>
<td>One</td>
<td>Two</td>
<td>Three</td>
</tr>
<tr>
<td>One</td>
<td>Two</td>
<td>Three</td>
</tr>
<tr>
<td>One</td>
<td>Two</td>
<td>Three</td>
</tr>
</table>
CSS
table {
width: 100%;
border-collapse: separate;
border-radius: 20px;
table-layout: fixed;
text-align: center;
font: 13px Verdana;
}
table tr {
border-radius: 20px;
}
table td {
border: 1px solid #000000;
padding: 20px;
background: red;
color: #ffffff;
}
table tr:first-child td:first-child {
border-radius: 20px 0 0 0;
}
table tr:first-child td:last-child {
border-radius: 0 20px 0 0;
}
table tr:last-child td:first-child {
border-radius: 0 0 0 20px;
}
table tr:last-child td:last-child {
border-radius: 0 0 20px 0;
}
I hope it will help you.
Fiddle: https://jsfiddle.net/xwqjgb5k/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With