css

How to add a border radius on a table row?


Does anyone know how to style a tr as we like?

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

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


Solution

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

    table {
      border-collapse: separate;
      border-spacing: 0;
    }
    
    td {
      border: solid 1px #000;
      border-style: none solid solid none;
      padding: 10px;
    }
    
    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; }
    
    tr:first-child td { border-top-style: solid; }
    tr td:first-child { border-left-style: solid; }
    <table>
      <tr>
        <td>1.1</td>
        <td>1.2</td>
        <td>1.3</td>
      </tr>
      <tr>
        <td>2.1</td>
        <td>2.2</td>
        <td>2.3</td>
      </tr>
      <tr>
        <td>3.1</td>
        <td>3.2</td>
        <td>3.3</td>
      </tr>
    </table>

    You can see it in action on JSFiddle too.