How to add border radius on table row

Css

Css Problem Overview


Does anyone know how to style tr as we like?

I've used border-collapse on table, after that tr's can display 1px solid border I give them.

However, when I've tried -moz-border-radius, it doesn't work. Even simple margin doesn't work.

Css Solutions


Solution 1 - Css

You can only apply border-radius to td, not tr or table. I've gotten around this for rounded corner tables by using these styles:

table { border-collapse: separate; }
td { border: solid 1px #000; }
tr:first-child td:first-child { border-top-left-radius: 10px; }
tr:first-child td:last-child { border-top-right-radius: 10px; }
tr:last-child td:first-child { border-bottom-left-radius: 10px; }
tr:last-child td:last-child { border-bottom-right-radius: 10px; }

Be sure to provide all the vendor prefixes. Here's an example of it in action.

Solution 2 - Css

Actual Spacing Between Rows

This is an old thread, but I noticed reading the comments from the OP on other answers that the original goal was apparently to have border-radius on the rows, and gaps between the rows. It does not appear that the current solutions exactly do that. theazureshadow's answer is headed in the right direction, but seems to need a bit more.

For those interested in such, here is a fiddle that does separate the rows and applies the radius to each row. (NOTE: Firefox currently has a bug in displaying/clipping background-color at the border radii.)

The code is as follows (and as theazureshadow noted, for earlier browser support, the various vendor prefixes for border-radius need added).

table { 
    border-collapse: separate; 
    border-spacing: 0 10px; 
    margin-top: -10px; /* correct offset on first border spacing if desired */
}
td {
    border: solid 1px #000;
    border-style: solid none;
    padding: 10px;
    background-color: cyan;
}
td:first-child {
    border-left-style: solid;
    border-top-left-radius: 10px; 
    border-bottom-left-radius: 10px;
}
td:last-child {
    border-right-style: solid;
    border-bottom-right-radius: 10px; 
    border-top-right-radius: 10px; 
}

Solution 3 - Css

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.

http://jsfiddle.net/Exe3g/

Solution 4 - Css

The tr element does honor the border-radius. Can use pure html and css, no javascript.

JSFiddle link: http://jsfiddle.net/pflies/zL08hqp1/10/

tr {
    border: 0;
    display: block;
    margin: 5px;
}
.solid {
    border: 2px red solid;
    border-radius: 10px;
}
.dotted {
    border: 2px green dotted;
    border-radius: 10px;
}
.dashed {
    border: 2px blue dashed;
    border-radius: 10px;
}

td {
    padding: 5px;
}

<table>
    <tr>
        <td>01</td>
        <td>02</td>
        <td>03</td>
        <td>04</td>
        <td>05</td>
        <td>06</td>
    </tr>
    <tr class='dotted'>
        <td>07</td>
        <td>08</td>
        <td>09</td>
        <td>10</td>
        <td>11</td>
        <td>12</td>
    </tr>
    <tr class='solid'>
        <td>13</td>
        <td>14</td>
        <td>15</td>
        <td>16</td>
        <td>17</td>
        <td>18</td>
    </tr>
    <tr class='dotted'>
        <td>19</td>
        <td>20</td>
        <td>21</td>
        <td>22</td>
        <td>23</td>
        <td>24</td>
    </tr>
    <tr class='dashed'>
        <td>25</td>
        <td>26</td>
        <td>27</td>
        <td>28</td>
        <td>29</td>
        <td>30</td>
    </tr>
</table>

Solution 5 - Css

According to Opera the CSS3 standard does not define the use of border-radius on TDs. My experience is that Firefox and Chrome support it but Opera does not (don't know about IE). The workaround is to wrap the td content in a div and then apply the border-radius to the div.

Solution 6 - Css

I think collapsing your borders is the wrong thing to do in this case. Collapsing them basically means that the border between two neighboring cells becomes shared. This means it's unclear as to which direction it should curve given a radius.

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. It might be easier to just define classes, such as .first-column and .last-column to serve this purpose.

Solution 7 - Css

Not trying to take any credits here, all credit goes to @theazureshadow for his reply, but I personally had to adapt it for a table that has some <th> instead of <td> for it's first row's cells.

I'm just posting the modified version here in case some of you want to use @theazureshadow's solution, but like me, have some <th> in the first <tr>. The class "reportTable" only have to be applied to the table itself.:

table.reportTable {
	border-collapse: separate;
	border-spacing: 0;
}

table.reportTable td {
	border: solid gray 1px;
	border-style: solid none none solid;
	padding: 10px;
}

table.reportTable td:last-child {
	border-right: solid gray 1px;
}

table.reportTable tr:last-child td{
	border-bottom: solid gray 1px;
}

table.reportTable th{
	border: solid gray 1px;
	border-style: solid none none solid;
    padding: 10px;
}

table.reportTable th:last-child{
	border-right: solid gray 1px;
	border-top-right-radius: 10px;
}

table.reportTable th:first-child{
	border-top-left-radius: 10px;
}

table.reportTable tr:last-child td:first-child{
	border-bottom-left-radius: 10px;
}	

table.reportTable tr:last-child td:last-child{
	border-bottom-right-radius: 10px;
}

Feel free to adjust the paddings, radiuses, etc to fit your needs. Hope that helps people!

Solution 8 - Css

I found that adding border-radius to tables, trs, and tds does not seem to work 100% in the latest versions of Chrome, FF, and IE. What I do instead is, I wrap the table with a div and put the border-radius on it.

<div class="tableWrapper">
  <table>
    <tr><td>Content</td></tr>
  <table>
</div>

.tableWrapper {
  border-radius: 4px;
  overflow: hidden;
}

If your table is not width: 100%, you can make your wrapper float: left, just remember to clear it.

Solution 9 - Css

Or use box-shadow if table have collapse

Solution 10 - Css

Use border-collapse:seperate; and border-spacing:0; but only use border-right and border-bottom for the tds, with border-top applied to th and border-left applied to only tr td:nth-child(1).

You can then apply border radius to the corner tds (using nth-child to find them)

https://jsfiddle.net/j4wm1f29/

<table>
  <tr>
    <th>title 1</th>
    <th>title 2</th>
    <th>title 3</th>
  </tr>
  <tr>
    <td>item 1</td>
    <td>item 2</td>
    <td>item 3</td>
  </tr>
  <tr>
    <td>item 1</td>
    <td>item 2</td>
    <td>item 3</td>
  </tr>
  <tr>
    <td>item 1</td>
    <td>item 2</td>
    <td>item 3</td>
  </tr>
  <tr>
    <td>item 1</td>
    <td>item 2</td>
    <td>item 3</td>
  </tr>
</table>
table {
  border-collapse: seperate;
  border-spacing: 0;
}

tr th,
tr td {
  padding: 20px;
  border-right: 1px solid #000;
  border-bottom: 1px solid #000;
}

tr th {
  border-top: 1px solid #000;
}

tr td:nth-child(1),
tr th:nth-child(1) {
  border-left: 1px solid #000;
}

/* border radius */
tr th:nth-child(1) {
  border-radius: 10px 0 0 0;
}

tr th:nth-last-child(1) {
  border-radius: 0 10px 0 0;
}

tr:nth-last-child(1) td:nth-child(1) {
  border-radius: 0 0 0 10px;
}

tr:nth-last-child(1) td:nth-last-child(1) {
  border-radius: 0 0 10px 0;
}

Solution 11 - Css

All the answers are way too long. The easiest way to add border radius to a table element that accepts border as a property, is doing border radius with overflow: hidden.

border: xStyle xColor xSize;
border-collapse: collapse;
border-radius: 1em;
overflow: hidden;

Solution 12 - Css

CSS:

tr:first-child th:first-child {
  border-top-left-radius: 70px;
  border-bottom-left-radius: 70px;
}

tr:first-child th:last-child {
  border-top-right-radius: 70px;
  border-bottom-right-radius: 70px;
}

Solution 13 - Css

Here's an example that puts a border with radius on a single row:

table { border-collapse: separate; border-spacing: 0; }

td { padding: 5px; }

.rowBorderStart {
  border: 1px solid #000;
  border-right: 0px;
  border-top-left-radius: 10px;
  border-bottom-left-radius: 10px;
}

.rowBorderMiddle {
  border: 1px solid #000;
  border-left: 0px;
  border-right: 0px;
}

.rowBorderEnd {
  border: 1px solid #000;
  border-left: 0px;
  border-top-right-radius: 10px;
  border-bottom-right-radius: 10px;
}

<table>
    <tr><td>1.1</td><td>1.2</td><td>1.3</td></tr>
    <tr><td class='rowBorderStart'>2.1</td><td class='rowBorderMiddle'>2.2</td><td class='rowBorderEnd'>2.3</td></tr>
    <tr><td>3.1</td><td>3.2</td><td>3.3</td></tr>
</table>

Solution 14 - Css

You can also use outline:

table {
  border-radius: 10px;
  outline: 1px solid gray;
}

Solution 15 - Css

I would Suggest you use .less instead, change your .css file to .less and use the following code:

table { 
  border-collapse: separate;
  border-spacing: 0; 
}
td {
    border: solid 1px #000;
    border-style: none solid solid none;
    padding: 10px;
}
tr td:first-child { 
  border-top-left-radius: 10px; 
  border-bottom-left-radius: 10px;
}
tr td:last-child { 
  border-top-right-radius: 10px; 
  border-bottom-right-radius: 10px;
}
tr td { 
  border-top-style: solid; 
}
tr td:first-child { 
  border-left-style: solid; 
}

tr{
  cursor: pointer;
}

tr:hover{
  td{
    background-color: red;
  }
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionHensonView Question on Stackoverflow
Solution 1 - CsstheazureshadowView Answer on Stackoverflow
Solution 2 - CssScottSView Answer on Stackoverflow
Solution 3 - CssRonni Egeriis PerssonView Answer on Stackoverflow
Solution 4 - CsshappyfunballView Answer on Stackoverflow
Solution 5 - CssRayView Answer on Stackoverflow
Solution 6 - CsslevikView Answer on Stackoverflow
Solution 7 - CssMathieu TurcotteView Answer on Stackoverflow
Solution 8 - CssScubaSteveView Answer on Stackoverflow
Solution 9 - CssSiviyView Answer on Stackoverflow
Solution 10 - CssJohn FotiosView Answer on Stackoverflow
Solution 11 - CssE Alexis MTView Answer on Stackoverflow
Solution 12 - Cssshahul01View Answer on Stackoverflow
Solution 13 - CssCraigoView Answer on Stackoverflow
Solution 14 - CssfcrozatierView Answer on Stackoverflow
Solution 15 - CssJones GabrielView Answer on Stackoverflow