Tuesday, August 2, 2022

[FIXED] How to break <td> inbetween multiple <td>?

Issue

I have the below html.

 <tr>
     <td class="slds-cell-wrap" data-label="">Category</td>
     <td class="slds-cell-wrap break" data-label=""><strong> Test </strong></td>
     <td class="slds-cell-wrap" data-label="">Format</td>
     <td class="slds-cell-wrap break" 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?


Solution

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 class="slds-cell-wrap" data-label="">Category</td>
     <td class="slds-cell-wrap break" data-label=""><strong> Test </strong></td>
     <td class="slds-cell-wrap" data-label="">Format</td>
     <td class="slds-cell-wrap break" data-label=""><strong>Test 1</strong></td>
  </tr>
</table>



Answered By - Alohci
Answer Checked By - Terry (PHPFixing Volunteer)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.