Setting max-height for table cell contents

前端 未结 7 1358
庸人自扰
庸人自扰 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 03:01

    I had the same problem with a table layout I was creating. I used Joseph Marikle's solution but made it work for FireFox as well, and added a table-row style for good measure. Pure CSS solution since using Javascript for this seems completely unnecessary and overkill.

    html

    content here
    lots of content here
    content here
    content here

    css

    .wrapper {height: 200px;}
    .table {position: relative; overflow: hidden; display: table; width: 100%; height: 50%;}
    .table-row {display: table-row; height: 100%;}
    .table-cell {position: relative; overflow: hidden; display: table-cell;}
    .cell-wrap {position: absolute; overflow: hidden; top: 0; left: 0; width: 100%; height: 100%;}
    

    You need a wrapper around the table if you want the table to respect a percentage height, otherwise you can just set a pixel height on the table element.

提交回复
热议问题