【发布时间】:2017-03-14 19:56:52
【问题描述】:
我有一个设置为 100% 宽度的表格,我希望获得其列的定义宽度。但是,我的所有列似乎都具有相同的宽度。
.table {
table-layout: fixed;
width: 100%;
}
.table th[colspan=4] {
/* width: 100%; */
}
.table td,
th {
border: 1px solid #AAA;
text-align: center;
}
.table td.one {
width: 10%;
}
.table td.two {
width: 20%;
}
.table td.three {
width: 50%;
}
.table td.four {
width: 20%;
}
<table class="table">
<tbody>
<tr>
<th colspan="4">All Four</th>
</tr>
<tr>
<th colspan="4">All Four</th>
</tr>
<tr>
<td class="one">A</td>
<td class="two">B</td>
<td class="three">C</td>
<td class="four">D</td>
</tr>
</tbody>
</table>
如果我删除表格上的宽度属性,它会尊重各个列的宽度。如果我将布局更改为table-layout: auto,那么它也可以工作。但是,如果我有一行跨越多列作为第一行,我就无法获得我想要的宽度。
【问题讨论】:
-
不,不是那样。我不是在为不同的行设置不同的宽度。这是关于在具有固定布局的 100% 宽度表中同时存在 colspan 和唯一宽度。
标签: html css html-table