如何将 html 表格最后一列的宽度设置为可用宽度的百分比?
我有一个有两列的表格。我通过将第一列的标题宽度设置为 30% 来设置第一列的宽度:
#TableFirstHeader
{
width: 30%;
}
效果很好,但如果我尝试将第二列标题的宽度设置为 65%:
#TableSecondHeader
{
width: 65%;
}
它会被忽略。我可以将该值设置为任何值,并且第二列始终延伸到表的末尾。
我真正想要的是第二列和表格右侧之间有大约 5% 的间隙。
我尝试通过设置宽度为 5% 的标题来创建一个空列,其中没有任何内容,但这没有任何作用。
我怎样才能让该列只使用可用总宽度的 65%(或者像可用宽度的 90%,这也可以)?
I've got a table with two columns. I set the width of the first column by settings its header's width to 30%:
#TableFirstHeader
{
width: 30%;
}
That works great, but if I try to set the width of the second header to 65%:
#TableSecondHeader
{
width: 65%;
}
it is simply ignored. I can set that value to anything, and the second column always stretches to the end of the table.
All I really want is about a 5% gap between the second column and the right side of the table.
I've tried creating an empty column by setting a header of width 5% with nothing in it, but that doesn't do anything.
How can I get that column to use only 65% of the total width available (or like 90% of the width available to it, that would be fine, too)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
第二个不一定需要分配宽度。你也可以用它
来代替。品味问题。
从这里编辑:
由于您在上面的评论中已经澄清,无论出于何种原因,行都需要是表格容器宽度的 100%,如果最后一列可能有额外的填充,我会支持 jeroen 的解决方案。
如果您必须将第二列设置为表格宽度的 65%(而不是 70%,右填充 5%):
空的第三列将会折叠。容器宽度为 100% 的空 div 可以防止这种行为。
The second th does not necessarily need to be assigned a width. Also you could use
instead. Matter of taste.
Edited from here:
Since you have clarified in the above comment, that - for whatever reason - the rows need to be 100% the table's container's width, I second jeroen's solution if the last column may have extra padding.
If you must have the second column at 65% the table's width (and not 70% with 5% right padding):
An empty third column would collapse. The empty div with 100% width of it's container prevents that behavior.
不能,表格的所有列组合在一起就构成了表格的宽度。
我不知道您到底想要实现什么,但也许您可以在最后一列的单元格上添加正确的填充,以获得您想要的效果或类似的效果。
You can´t, all columns of a table combined make up the width of the table.
I don´t know what you are trying to achieve exactly, but perhaps you can add a right padding on the cells of the last column to get the effect you want or something similar.