Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

border around row cells

How to make an outer border around all cells in a row? Check the example in the bottom with the green border

https://jsfiddle.net/Lgb91rhw/

body {
  background: red;
}

table {
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 0 30px;
}

td {
  padding: 15px 6px;
  background: #fff;
}
<table>
  <tr>
    <td>some data row 1</td>
    <td>some data row 1</td>
  </tr>
  <tr>
    <td>some data row 2</td>
    <td>some data row 2</td>
  </tr>
</table>

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

There are a few ways. Use outline on the tr element to put a border outside the td elements.

body {
  background: red;
}

table {
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 0 30px;
}

td {
  padding: 15px 6px;
  background: #fff;
}

tr {
  outline: 2px solid #0f0;
}
<table>
  <tr>
    <td>some data row 1</td>
    <td>some data row 1</td>
  </tr>
  <tr>
    <td>some data row 2</td>
    <td>some data row 2</td>
  </tr>
</table>

Or alternatively style each td element and the :first-child and :last-child to put the borders on the end.

body {
  background: red;
}

table {
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 0 30px;
}

td {
  padding: 15px 6px;
  background: #fff;
  border-top: 2px solid #0f0;
  border-bottom: 2px solid #0f0;
}

td:first-child {
  border-left: 2px solid #0f0;
}

td:last-child {
  border-right: 2px solid #0f0;
}
<table>
  <tr>
    <td>some data row 1</td>
    <td>some data row 1</td>
  </tr>
  <tr>
    <td>some data row 2</td>
    <td>some data row 2</td>
  </tr>
</table>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading