Home > Enterprise >  How to break <td> inbetween multiple <td>?
How to break <td> inbetween multiple <td>?

Time:07-21

I have the below html.

 <tr>
     <td  data-label="">Category</td>
     <td  data-label=""><strong> Test </strong></td>
     <td  data-label="">Format</td>
     <td  data-label=""><strong>Test 1</strong></td>
</tr>

I want the output to be like below.

Category Format
Test     Test1

Note that the 2nd <td> and the 4th <td> are in a new line.

How do I achieve this using css?

CodePudding user response:

You do not need to use CSS for this table all you need is HTML. For the table headers, you have to put a <th> tag inside a <tr> tag so it goes something like this:

  <table>
  <tr>
    <th  data-label="">Category</th>
    <th  data-label="">Format</th>
  </tr>
  <tr>  
    <td  data-label=""><strong> Test </strong></td>
    <td  data-label=""><strong>Test 1</strong></td>
  </tr>
</table>

CodePudding user response:

display:grid is ideal for this.

tr {
  display: grid;
  grid-template-columns: auto auto;
  column-gap: 0.5em;
}
td.break {
  grid-row: 2;
}
  
<table>
   <tr>
     <td  data-label="">Category</td>
     <td  data-label=""><strong> Test </strong></td>
     <td  data-label="">Format</td>
     <td  data-label=""><strong>Test 1</strong></td>
  </tr>
</table>

  • Related