I have a table html like the following:
<table>
<tbody>
<tr>
<th>Header 1</th>
<td>Data 1</td>
<th>Header 2</th>
<td>Data 2</td>
</tr>
<tr>
<th>Header 3</th>
<td>Data 3</td>
<th>Header 4</th>
<td>Data 4</td>
<th>Header 5</th>
<td>Data 5</td>
</tr>
</tbody>
</table>
I want the table to look something like this:
Header1 Header2
td1 td2
Header3 Header4 Header5
td3 td4 td5
Can this be achieved using CSS without changing the html structure?
2
Answers
Please follow table tags structure rules.
BUT if you insist to use Table tags.
Try table nesting
OR use BR or styling the div for heading and data
You could lay the table out as a grid:
Note: I don’t necessarily recommend this unless you are really stuck with that weird HTML structure and it absolutely can’t be changed. The semantics are a mess with the given structure, the th should be in the first row as headings. However, if you are truly stuck with the structure then grid will lay things out the way you want.