I understood that this might have been answered before but I am unable to wrap my head around how to create a multi layered colspan in html table
I have this html table from w3schools, however I want to create a colspan of 2 in the Data 2 and Data 5
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
</style>
</head>
<body>
<table style="width:100%">
<tr>
<th colspan="3">Head1</th>
<th>Head2</th>
</tr>
<tr>
<td>Data 1</td>
<th colspan="2">
<tr>
<td>Data 2a</td>
<td>Data 2b</td>
</tr>
</th>
<td>Data 3</td>
</tr>
<tr>
<td>Data 4</td>
<th colspan="2">
<tr>
<td>Data 5a</td>
<td>Data 5b</td>
</tr>
</th>
<td>Data 6</td>
</tr>
</table>
</body>
</html>
However, colspan is not colspanning. I know my approach for this problem is wrong. How should I proceed with this?
Note: this is just a simplified version of the current table on the project that I am working on.
2
Answers
This structure should achieve the expected output where Data 2 and Data 5 span across two columns each.
Try this. Add TR as per your need.