Setting max-height for table cell contents

前端 未结 7 1352
庸人自扰
庸人自扰 2020-12-03 02:06

I have a table which should always occupy a certain percentage of the height of the screen. Most of the rows are of fixed height, but I have one row that should stretch to f

7条回答
  •  佛祖请我去吃肉
    2020-12-03 02:53

    What I found !!!, In tables CSS td{height:60px;} works same as CSS td{min-height:60px;}

    I know that situation when cells height looks bad . This javascript solution don't need overflow hidden.

    For Limiting max-height of all cells or rows in table with Javascript:

    This script is good for horizontal overflow tables.

    This script increase the table width 300px each time (maximum 4000px) until rows shrinks to max-height(160px) , and you can also edit numbers as your need.

    var i = 0, row, table = document.getElementsByTagName('table')[0], j = table.offsetWidth;
    while (row = table.rows[i++]) {
        while (row.offsetHeight > 160 && j < 4000) {
            j += 300;
            table.style.width = j + 'px';
        }
    }
    

    Source: HTML Table Solution Max Height Limit For Rows Or Cells By Increasing Table Width, Javascript

提交回复
热议问题