CSS 如何在CSS中控制表格的tr高度

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

How to control tr height of table in CSS

csstablerowcss-tables

提问by Kurt

I try to reduce the white space between each trin a table.

我尝试减少tr表格中每个之间的空白。

I have set "table id='recTable' cellspacing=\"0\" cellpadding=\"0\"", that means there is no space between each tr(comfirmed). So what only I need to do is reduce the height of tritself.

我已经设置了"table id='recTable' cellspacing=\"0\" cellpadding=\"0\"",这意味着每个tr(确认)之间没有空格。所以我唯一需要做的就是降低tr自身的高度。

I used "height:40px;"for doing this, but it doest work, no change.

我曾经"height:40px;"这样做过,但它不起作用,没有改变。

It always shows a 70px height. But if I set a big height like "height:100px;", which the height is more than 70px, then it will change to the height I set.

它总是显示一个70px height. 但是如果我设置了一个很大的高度,比如"height:100px;"高度超过70px,那么它就会变成我设置的高度。

How can I do it?

我该怎么做?

回答by Jason Gennaro

You can set this explicitly in your css. For example:

您可以在 css 中明确设置它。例如:

table#recTable{width:100%; border:1px solid red;}
#recTable tr td {height:40px; border:1px solid red;}

HTML

HTML

<table id="recTable">
    <tr><td>Something</td></tr>
    <tr><td>Something else</td></tr>
</table>

http://jsfiddle.net/jasongennaro/qXpLM/

http://jsfiddle.net/jasongennaro/qXpLM/

Borders just for example

仅以边框为例

回答by Barry Kaye

You need to set the height or line-height of your TD's or TH's within your TR.

您需要在 TR 内设置 TD 或 TH 的高度或行高。

回答by Snehlata Shaw

It's better to have a div element inside td element and fix the height of div element. It worked for me.

最好在 td 元素内部有一个 div 元素并固定 div 元素的高度。它对我有用。

 <tr>
    <td>
       <div style="max-height:92px;">
         <span style="color: #992222; font-size:36pt;font-family:Arial Baltic;">
         "     </span>
       </div>
   </td>
 </tr>