How to make all the rows of a table the same height as the biggest one

不羁岁月 提交于 2019-12-11 03:22:29

问题


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?


回答1:


It's not possible with pure CSS.

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.



来源:https://stackoverflow.com/questions/10701562/how-to-make-all-the-rows-of-a-table-the-same-height-as-the-biggest-one

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!