【发布时间】:2019-03-11 20:41:18
【问题描述】:
我正在使用带有 w3-table 类的 w3css。 我为每个“td”设置了宽度,宽度为 35px,高度为 35px。 我发现宽度仍然根据文本而变化。
这是我的代码:
<!DOCTYPE html>
<html>
<title>W3.CSS</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/lib/w3.css">
<style>
.box{
width: 35px;
height: 35px;
border: 1px solid black;
}
.yellow {
background-color: yellow !important;
}
</style>
<body>
<table class="w3-table">
<tbody>
<tr>
<td class="box yellow">20</td>
<td class="box yellow">1000</td>
<td class="box yellow">2</td>
<td class="box yellow">10</td>
<td class="box yellow">1000</td>
</tr>
<tr>
<td class="box yellow"> </td>
<td class="box yellow"> </td>
<td class="box yellow"> </td>
<td class="box yellow"> </td>
<td class="box yellow"> </td>
</tr>
</tbody>
</table>
</body>
</html>
我附上结果输出如下:
为了便于我解释,标有 A、B、C、D、E 列。 A 带文字 20 B 带文字 1000 C 与文本 2 D 带文字 10 E 带文字 1000
A 和 D 列有两位数的文本,即分别为 20 和 10。 我预计 A 和 D 具有相同的宽度,但输出结果显示 A 宽度略大于 D。我可以得出结论,与其他列相比,第一列总是略大。 我还注意到列宽会根据文本数量而变化。 示例 B 列中的 1000 和 C 列中的 E 宽度大于 2。
我可以知道如何确保列宽能够在每列中保持固定的大小比例,同时能够保持响应式网页吗?
如果您能给我一些提示,我将不胜感激。
【问题讨论】:
-
你的想法是错误的。当表格的宽度为 100% 时,为什么要为每列提供固定的 35px 宽度?这是你的问题的原因。需要时使用百分比和最小/最大宽度属性。
-
如果您能通过更改的源代码向我展示一个正确的想法,我将不胜感激。谢谢。
标签: html css html-table w3.css