計算列的高度不同我有以下佈局的表:Safari瀏覽器從其他瀏覽器
<table>
<thead>
<tr>
<th rowspan="3" class="first-column">1. First column</th>
<th class="top-cell">1. Second column</th>
<th class="top-cell">1. Third column</th>
</tr>
<tr>
<th class="bottom-cell">2. Second column</th>
<th class="bottom-cell">2. Third column</th>
</tr>
<tr>
<th class="bottom-cell">3. Second column</th>
<th class="bottom-cell">3. Third column</th>
</tr>
</thead>
</table>
CSS:
table .first-column {
height: 200px;
}
th
標籤與.first-column
類總是有固定的高度。 .bottom-cell
也可以固定高度,如果需要的話(我已經嘗試了這種方法,但它沒有解決問題)。 top-cell
必須有動態高度。
而這個表格顯示爲我想在Firefox和Chrome中:列的高度設置成彼此成比例。
但Safari以不同的方式顯示它,它只是通過內容將高度設置爲前兩列,並拉伸最後一行以填充剩餘空間。但我想做到這一點的結果之一:
有任何解決方法,以顯示在Safari列,Firefox或Chrome呢?我知道如何用js做到這一點,所以我正在尋找一個純CSS的解決方案。
我已經嘗試設置爲.bottom-cell
固定高度:
table .bottom-cell {
height: 20px;
}
我也試圖在.bottom-cell
的固定高度calc
功能結合起來,.top-cell
:
table .bottom-cell {
height: 20px;
}
table .top-cell {
height: calc(100% - 40px);
}
感謝您的回答!幸運的是,我不需要支持IE。 2.我沒有添加'tbody'部分,因爲它與此問題無關。第一行的第一列總是具有固定的高度。我也嘗試在最後兩個'tr'標籤中爲'td'設置固定高度,但它也沒有幫助。我看到我沒有提供足夠的信息。我要更新我的答案,因此它變得更加清晰。 –
@fakerun我已經使用演示和代碼示例更新了我的答案,以向您展示如何定義表格以使其在所有三個瀏覽器中正確顯示。讓我知道如果它不起作用。 – BenCodeZen
是的,我知道它會在這種情況下起作用。但是我不能爲所有'td'標籤設置固定高度,因爲第一行的'td.top-cell'是動態的,可以有任何高度。第一行的每一列不僅包含文本,還包含大量數據,而我只放置文本以保持簡單的問題。澄清:我可以爲所有'td' expect'td.top-cell'設置固定的高度。 –