2016-03-03 60 views
0

我搜索一個表,每次trs高度是相同的。表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; 
} 
+0

添加您的HTML以及更好地創建一個片段或小提琴。 –

+0

JavaScript是一個選項嗎?您可以編寫一個函數,快速檢查所有「」元素的高度,然後將它們全部設置爲找到的最高值。 – Starscream1984

+0

@ Starscream1984當然,我也實現了jquery –

回答

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); 

你可以用它在功能,如果您需要重新計算,例如當日歷項目被添加/刪除時