html - 表格中不规则间距的列
问题描述
我正在尝试创建一个表格,该表格分为具有 2 个标题的部分;一个在顶部,一个在底部。顶部将有 3 个标题和 3 列<td>
。第二个将有一个长标题、2 列和一个长页脚。我无法让底部的 2 列跨越表格的长度(它们当前与上部的前 2 列对齐。
我试过使用 `colspan="1.5" (我的逻辑是如果 colspan="3",那么一半会起作用)以及 width="550px;" (表格的全宽为 1000px)。关于我为实现这一目标所做的任何建议?代码如下(注意:这是一个使用 DOM 节点动态创建表的 javascript 应用程序;我现在只是使用内联 css 将其放入其中)。
supplemental_dialog.innerHTML = "<h6>Map Date: " + this_date + "</h6>" +
"<div class='row' style='height:100px;'>" +
"<div><h5>Location Information</h5>" +
"<table id='table2' width=100%>" +
"<tr width=100%>" +
"<th><b>Flood Event</b></th>" + "<th><b>Estimated Flood Depth*</b></th>" + "<th><b>Estimated Base Flood Elevation*</b></th>" +
"</tr>" +
"<tr width=100%>" +
"<td width=33%>0.2 Percent (500 Year)</td><td width=33%>" + "14.5 feet above land surface" + "</td>" + "<td width=33%>" + "496.4 feet NAVD 1988" + "</td > " +
"</tr>" +
"<tr width=100%>" +
"<td width=33%>0.2 Percent (500 Year)</td><td width=33%>" + "14.5 feet above land surface" + "</td>" + "<td width=33%>" + "496.4 feet NAVD 1988" + "</td > " +
"</tr>" +
"<tr width=100%>" +
"<td width=33%>0.2 Percent (500 Year)</td><td width=33%>" + "14.5 feet above land surface" + "</td>" + "<td width=33%>" + "496.4 feet NAVD 1988" + "</td > " +
"</tr>" +
"<tr width=100%>" +
"<td width=33%>0.2 Percent (500 Year)</td><td width=33%>" + "14.5 feet above land surface" + "</td>" + "<td width=33%>" + "496.4 feet NAVD 1988" + "</td > " +
"</tr>" +
"<tr width=100%>" +
"<th colspan='3' width=100% style='text-align:center'><b>Probability of Flooding </b></td>" +
"</tr>" +
"<tr width=100%>" +
"<td width='500px'>0.2 Percent (500 Year)</td><td width='500px'>" + "14.5 feet above land surface" + "</td>" +
"</tr>" +
"<tr width=100%>" +
"<td width='500px'>0.2 Percent (500 Year)</td><td width='500px'>" + "14.5 feet above land surface" + "</td>" +
"</tr>" +
"<tr width=100%>" +
"<td colspan='3' width=100%><p style='font-size: 10px;'>*The information included in this report is based on the entire building footprint, or, if clicked outside of a building footprint, based on the point clicked on the map. Results are not considered an official determination.</p></td>" +
"</tr>" +
"</table></div > " +
"</div>";
解决方案
一种简单的方法是为不同行中的不同单元格添加适当的 colspan 值,请参见示例:
<html>
<head>
<style>
table,
th,
td {
border: 1px solid black;
}
</style>
</head>
<body>
<table>
<tr>
<th colspan="2">first col</th>
<th colspan="2">second col</th>
<th colspan="2">third col</th>
</tr>
<tr>
<td colspan="2">a</td>
<td colspan="2">b</td>
<td colspan="2">c</td>
</tr>
<tr>
<td colspan="3">d</td>
<td colspan="3">e</td>
</tr>
<tr>
<td colspan="6">f</td>
</tr>
</table>
</body>
</html>
推荐阅读
- spring-boot - JPA Hibernate 使用 @joincolumn 为 @ManyToOne
- javascript - 未捕获的 SyntaxError:JSON 输入意外结束:在 JSON.parse(
) - java - Java使用@value构造成员字段大小
- python - Python pandas:根据组内的最大值创建新列,但使用附加(字符串)列中的值
- javascript - 提交表单后显示带有收据的模式(Codeigniter)
- javascript - 我正在用 HTML 创建一个登录系统……我用过写了一段代码,但它似乎没有工作……请求回答
- javascript - 需要在 tinyMCE 编辑器中同时具有 p 标签和 br 标签
- mysql - MySQL .IBD 文件被意外修改,原因是数据库损坏如何恢复它
- r - 在ggplot的x轴上以适当的顺序放置时间(月/年)
- android - HostnameVerifier 您的应用程序正在使用 HostnameVerifier 接口的不安全 iImplementation。如何解决此问题?