I am trying to create a table with colspan and rowspan inside.
<!DOCTYPE html>
<html>
<head>
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid black;
text-align: left;
padding: 8px;
}
.top {
background-color: yellow;
}
.left {
background-color: blue;
}
.right {
background-color: green;
}
</style>
</head>
<body>
<h2>HTML Table</h2>
<table class="">
<tbody>
<tr>
<td rowspan="2"></td>
<td colspan="5"></td>
<td colspan="2" rowspan="2"></td>
<td colspan="3" rowspan="2"></td>
</tr>
<tr>
<td class="top" colspan="5"></td>
</tr>
<tr>
<td rowspan="5"></td>
<td class="left" colspan="1"></td>
<td class="left" colspan="1"></td>
<td class="right" colspan="8"></td>
</tr>
<tr>
<td class="left" colspan="1"></td>
<td class="left" colspan="1"></td>
<td class="right" colspan="8"></td>
</tr>
<tr>
<td class="left" colspan="1"></td>
<td class="left" colspan="1"></td>
<td class="right" colspan="8"></td>
</tr>
<tr>
<td class="left" colspan="1"></td>
<td class="left" colspan="1"></td>
<td class="right" colspan="8"></td>
</tr>
<tr>
<td class="left" colspan="2"></td>
<td class="left" ></td>
<td class="right" colspan="7"></td>
</tr>
<tr>
<td rowspan="1"></td>
<td colspan="10"></td>
</tr>
<tr>
<td rowspan="1"></td>
<td colspan="10"></td>
</tr>
</tbody>
</table>
</body>
</html>
I want to make the last blue/green to be the same with the first 4 rows. But when I change it to use the same colspan values, below is the result.
<!DOCTYPE html>
<html>
<head>
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid black;
text-align: left;
padding: 8px;
}
.top {
background-color: yellow;
}
.left {
background-color: blue;
}
.right {
background-color: green;
}
</style>
</head>
<body>
<h2>HTML Table</h2>
<table class="">
<tbody>
<tr>
<td rowspan="2"></td>
<td colspan="5"></td>
<td colspan="2" rowspan="2"></td>
<td colspan="3" rowspan="2"></td>
</tr>
<tr>
<td class="top" colspan="5"></td>
</tr>
<tr>
<td rowspan="5"></td>
<td class="left" colspan="1"></td>
<td class="left" colspan="1"></td>
<td class="right" colspan="8"></td>
</tr>
<tr>
<td class="left" colspan="1"></td>
<td class="left" colspan="1"></td>
<td class="right" colspan="8"></td>
</tr>
<tr>
<td class="left" colspan="1"></td>
<td class="left" colspan="1"></td>
<td class="right" colspan="8"></td>
</tr>
<tr>
<td class="left" colspan="1"></td>
<td class="left" colspan="1"></td>
<td class="right" colspan="8"></td>
</tr>
<tr>
<td class="left" colspan="1"></td>
<td class="left" colspan="1"></td>
<td class="right" colspan="8"></td>
</tr>
<tr>
<td rowspan="1"></td>
<td colspan="10"></td>
</tr>
<tr>
<td rowspan="1"></td>
<td colspan="10"></td>
</tr>
</tbody>
</table>
</body>
</html>
It rearranges the table’s width. I want to keep the initial width based on colspan and rowspan.
I guess the issue lies with the colspan/rowspan values added but I don’t know where.