简体   繁体   English

溢出和最大高度

[英]Overflow and max-height

I am trying to set up a scrolling table with a maximum height, and to do that I have: 我正在尝试设置一个最大高度的滚动表,为此,我有:

<table>
<tbody style="height: 300px; overflow:auto;">
//php for loop, populating table with <tr>s/<td>s
</tbody>
</table>

This works fine, but if there is only one or two rows they are stretched to fit the 300px height. 这样可以正常工作,但是如果只有一行或两行,它们会被拉伸以适应300px的高度。 I switched height to max-height but then the scroll bars never appeared, no matter how large the table got. 我将高度切换到最大高度但是滚动条从未出现过,无论桌子有多大。 Where am I going wrong? 我哪里错了?

I don't know why the tr's and td's are filling the height up when there are few, but you could do a couple things I think. 我不知道为什么tr和td在很少的时候填满了高度,但你可以做几件事我想。

Try styling the cells to be a certain height, or even don't style anything to a height, and style the div that the table is in to a height. 尝试将单元格设置为某个高度,或者甚至不要将任何内容设置为高度,并将表格所在的div设置为高度。 I've done the latter, and it works for me. 我做了后者,它对我有用。 The cells all stay a normal height, depending on whats in them. 细胞都保持正常高度,具体取决于它们中的含量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM