如何使表的所有行与最大的一样的高度 [英] How to make all the rows of a table the same height as the biggest one
问题描述
我试图使表格的所有行与其中具有最长文本的表格的高度相同。相应地扩展。
I am trying to make all the rows of a table the same height as the one that has the longest text in it, expanding accordingly.
但我实现的在阅读完后给他们一个固定的高度:
如何强制表中的所有行具有相同的高度
But all I achieved is give them a fixed height after reading this: how can i force all rows in a table to have the same height
这意味着我需要预测我应该在其中放置多少文本,这显然是不可预测的。
This means that I need to predict how much text I should put in it which is obviously not predictable. Is it possible with CSS or do I need using Javascript?
推荐答案
使用纯CSS不可能。
可以使用javascript。例如,使用jQuery你可以写如下
It's possible to do it with javascript. For example, with jQuery you could write something like
var maxHeight = null;
$(<MY LINES>).each(function() {
var thisHeight = $(this).height();
if(maxHeight == null || thisHeight > maxHeight) maxHeight = thisHeight;
}).height(maxHeight);
不要忘记处理边界案例,并在行中包括最大和最小高度。
Don't forget to handle borderline cases and to include a maximum and a minimum height to your lines.
这篇关于如何使表的所有行与最大的一样的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!