Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Border radius and border together in a table td

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>
like image 342
Bhuwan Avatar asked Jan 22 '18 07:01

Bhuwan


People also ask

How to give a border radius to each corner of TD?

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.

Does border-radius affect tables with border-collapse?

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.

How to add border radius to a table element?

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.

What is the use of border radius?

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:


2 Answers

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>
like image 92
satyajit rout Avatar answered Sep 18 '22 18:09

satyajit rout


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/

like image 22
Muhammad Awais Iqbal Avatar answered Sep 17 '22 18:09

Muhammad Awais Iqbal