在 HTML 中设置表格的高度无效
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14809502/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Setting the height of a table in HTML has no effect
提问by Em Sta
Why does this table height not function?
为什么这个桌子高度不起作用?
<table border=1 bgcolor="green" width=80% height="30%">
<tr>
<td rowspan="2" >
This is 1st row 1st column
</td>
<td >
2
</td>
</tr>
</table>
回答by oezi
just add the following to your css:
只需将以下内容添加到您的 css 中:
html, body{
height: 100%;
}
As other said, a table
doesn't have a height
-attriute, but most browsers intrepet that anyway. you can see the result on jsfiddle.
正如其他人所说, atable
没有height
-attriute,但无论如何大多数浏览器都会这样做。你可以在 jsfiddle 上看到结果。
The reason you need to do this is that the parent element of anything that should have a height in % must have a height too (as Shadow Wizard said: "30% of what exactly?" - the parent has to have a height).
您需要这样做的原因是任何应该具有 % 高度的父元素也必须具有高度(正如 Shadow Wizard 所说:“究竟是什么的 30%?” - 父元素必须具有高度)。
回答by Kevin Bowersox
The table
tag does not contain a height
attribute. Try setting the height of the table using CSS styling.
该table
标签不包含height
属性。尝试使用 CSS 样式设置表格的高度。
table{
height: 30%;
}
回答by arvind
<div style="height: 200px; overflow-y: scroll;">
<table border=1 bgcolor="green">
<tr>
<td rowspan="2" >
This is 1st row 1st column
</td>
<td>
2
</td>
</tr>
</table>
</div>
回答by GKirov
I just had the same issue.
I have table inside a container ( div config-table
), just setting height
didn't work for me. I had to set overflow: auto
( for my case auto
was needed ) and now work
我只是有同样的问题。我在容器( div config-table
)中有一张桌子,只是设置height
对我不起作用。我必须设置overflow: auto
(因为我的情况auto
需要)现在工作
.config-table {
height: 350px;
overflow: auto;
}