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

Span only text in a HTML table

Is possible span only the text in a HTML table?
I need that the text span in 3 columns but I must keep the background color of the cells different: example first cell red, secon cell green third cell red

<table>
  <tr>
    <th>1</th>
    <th>2</th>
    <th>3</th>
  </tr>
  <tr>
    <td colspan="3" bgcolor="red">abcdefgh</td>
    <td bgcolor="green"></td>
    <td bgcolor="red"></td>
  </tr>
</table>

This is what I want to achieve

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 :

You can create a linear gradient for the background of the first/spanned cell that uses abrupt changes between the different colors (and delete the superfluous empty cells):

table {
  border-collapse: collapse;
}

td,
th {
  border: 1px solid grey;
}

.x {
  background: linear-gradient(270deg, #FF0101 0% 33.33%, #5BA25F 33.34% 66.66%, #FF0101 66.67% 100%);
}
<table>
  <tr>
    <th>1</th>
    <th>2</th>
    <th>3</th>
  </tr>
  <tr>
    <td colspan="3" class="x">abcdefghoiuasdfijawerhkgkjbyxc</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