我搜索了一个 tr 高度每次都相同的表。
例如:
即使我添加了一行,高度也应该保持不变。
我可以用百分比来做,因为我不知道我得到了多少行(日历)。
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;
}
最佳答案
正如您所说您正在使用 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);
如果您需要重新计算,例如添加/删除日历元素时,您可以将其包装在一个函数中
关于html - 表tr同高动态行数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35777845/