修复 HTML 表格中表格行的高度

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/593849/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 23:22:19  来源:igfitidea点击:

Fix height of a table row in HTML Table

html

提问by Billy

Kindly look at the following code:

请看下面的代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
</head>
<body>
<table id="content" height="525" border="0" cellspacing="0" cellpadding="0">
<tr style="height:9px"><td height="9" bgcolor="#990000">Upper</td></tr>
<tr><td  bgcolor="#990099">Lower</td></tr>
</table>
</body>
</html>

IE ignores the "height:9px" and I can't get what I want. Also, without the DOCTYPE, it works. But I have to follow the standard so that DOCTYPE cannot be removed. Does anyone how to fix the height of the upper row?

IE 忽略了“height:9px”,我无法得到我想要的。此外,如果没有 DOCTYPE,它也能工作。但是我必须遵循标准,以便无法删除DOCTYPE。有没有人如何固定上排的高度?

Some clarifications: 1. The height of second row may vary according to users' action and cannot be fixed. 2. The height of the table is set to 525px so the table has a minimum height of 525px

一些说明: 1. 第二排的高度可能会根据用户的操作而有所不同,并且无法固定。2.表格的高度设置为525px所以表格的最小高度为525px

采纳答案by roman m

the bottom cell will grow as you enter more text ... setting the table width will help too

底部单元格会随着您输入更多文本而增长...设置表格宽度也会有所帮助

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
</head>
<body>
<table id="content" style="min-height:525px; height:525px; width:100%; border:0px; margin:0; padding:0; border-collapse:collapse;">
<tr><td style="height:10px; background-color:#900;">Upper</td></tr>
<tr><td style="min-height:515px; height:515px; background-color:#909;">lower<br/>
</td></tr>
</table>
</body>
</html>

回答by roman m

This works, as long as you remove the height attribute from the table.

只要您从表格中删除高度属性,这就会起作用。

<table id="content" border="0px" cellspacing="0px" cellpadding="0px">
  <tr><td height='9px' bgcolor="#990000">Upper</td></tr>
  <tr><td height='100px' bgcolor="#990099">Lower</td></tr>
</table>

回答by shery

my css

我的 CSS

TR.gray-t {background:#949494;}
h3{
    padding-top:3px;
    font:bold 12px/2px Arial;
}

my html

我的 HTML

<TR class='gray-t'>
<TD colspan='3'><h3>KAJANG</h3>

I decrease the 2nd size in font.

我减小了字体的第二个大小。

padding-topis used to fix the size in IE7.

padding-top用于固定 IE7 中的大小。