表tr相同的高度动态行数

时间:2016-03-03 16:35:42

标签: html css css-tables

我每次都搜索一个高度为tr的表。

例如:

enter image description here

即使我添加一行,高度应该保持不变。

我可以用百分比来做,因为我不知道我得到了多少行(日历)。

CSS:

 .cMid-Calender table{
    width:100%;
    height:calc(100% - 95px);
    table-layout:fixed;
    border-collapse: collapse;
    text-align:center; 
}
.cMid-Calender th{
    font-size: 14px;
    height:30px;
    font-weight: 300;
    color:#f333;
    text-align: left;
    padding-left:10px;
    background-color:#f8f8f8;
    height:25px;
}
.cMid-Calender td{
    border-top:1px solid #eaeaea;
    font-size: 22px;
    font-weight: 200;
    cursor: pointer;
    overflow: hidden;
    color:#767676;
    padding:0px;
    vertical-align: top;
    text-align: left;
}

1 个答案:

答案 0 :(得分:2)

如你所说,你正在使用jquery,那么你应该可以做这样的事情:

var maxHeight = 0;

// loop through and keep track of biggest height
$(".cMid-Calender td").each(function(index) {
    if($(this).height() > maxHeight) {
        maxHeight = $(this).height();
    };
});

// set all elements to the biggest height
$(".cMid-Calender td").height(maxHeight);

如果需要重新计算,可以将其包装在函数中,例如添加/删除日历项时