[英]Create this table using a single classic html table element and rowspan/colspan
I am trying to create a table that looks like this using classic HTML table constructs: 我试图使用经典的HTML表结构创建一个看起来像这样的表:
Thinking left to right I came up with the following HTML which was a disaster. 从左到右思考,我想到了以下HTML,这简直是一场灾难。 Am I missing something? 我想念什么吗?
<html>
<body>
<table border = 1 width=640 height=480>
<tr>
<td rowspan=2 colspan=2>1</td>
<td rowspan=4 colspan=4>2</td>
<td rowspan=2 colspan=2>3</td>
<tr>
<td rowspan=2 colspan=2>4</td>
<td rowspan=2 colspan=2>5</td>
</tr>
<tr>
<td rowspan=4 colspan=4>6</td>
<td rowspan=2 colspan=2>7</td>
<td rowspan=1 colspan=1>8</td>
<td rowspan=1 colspan=1>9</td>
</tr>
<tr>
<td rowspan=1 colspan=1>10</td>
<td rowspan=1 colspan=1>11</td>
</tr>
<tr>
<td rowspan=2 colspan=2>12</td>
<td rowspan=2 colspan=2>13</td>
</tr>
</table>
</body>
</html>
Here is the code for you. 这是给您的代码。 I hope this becomes useful to you because I spent an hour trying to create this for you. 我希望这对您有用,因为我花了一个小时尝试为您创建它。 (notice HTML 5 recommends using CSS but since you wanted this in just classic html here is the solution for you) (注意,HTML 5建议使用CSS,但是由于您只想在经典html中使用它,因此这里为您提供了解决方案)
<table width="800" height="400">
<tr width=50%>
<td width="33%" bgcolor="#6CBB3C"></td>
<td width="33%" rowspan="2" bgcolor="#C24641" width=40%></td>
<td width="33%" bgcolor="#6CBB3C"></td>
</tr>
<tr width=50%>
<td width="33%" bgcolor="#6CBB3C"></td>
<td width="33%" bgcolor="#6CBB3C"></td>
</tr>
</table>
<table width="800" height="400">
<tr width="50%">
<td width="50%" rowspan="2" bgcolor="#C24641" width=40%></td>
<td width="25%" bgcolor="#6CBB3C"></td>
<td width="25%" bgcolor="#6CBB3C" height="200pix" bgcolor="white">
<table width="100%" height="200pix" bordercolor="white"
bgcolor="white">
<tr>
<td bgcolor="#7A5DC7"></td>
<td bgcolor="#7A5DC7"></td>
</tr>
<tr>
<td bgcolor="#7A5DC7"></td>
<td bgcolor="#7A5DC7"></td>
</tr>
</table>
</td>
</tr>
<tr width="50%">
<td bgcolor="#6CBB3C"></td>
<td bgcolor="#6CBB3C"></td>
</tr>
</table>
here is the result for you: 这是给您的结果:
One table styled with CSS. 一张用CSS样式的表格。
HTML 的HTML
<table>
<tr>
<td class="green"></td>
<td colspan="2" rowspan="2" class="red"></td>
<td class="green" colspan="2"></td>
</tr>
<tr>
<td class="green"></td>
<td class="green" colspan="2"></td>
</tr>
<tr>
<td colspan="2" rowspan="3" class="red"></td>
<td rowspan="2" class="green"></td>
<td class="blue"></td>
<td class="blue"></td>
</tr>
<tr>
<td class="blue"></td>
<td class="blue"></td>
</tr>
<tr>
<td class="green"></td>
<td colspan="2" class="green"></td>
</tr>
</table>
CSS 的CSS
table {
table-layout: fixed;
border-collapse: collapse;
max-width: 8em;
width: 100%;
}
td {
border: 1px solid white;
}
.green {
background: rgb(155,187,89);
height: 2em;
width: 2em;
}
.red {
background: rgb(192,80,77);
height: 4em;
width: 4em;
}
.blue {
background: rgb(79,129,189);
height: 1em;
width: 1em;
}
Result 结果
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.