将DIV调整到表格中的最大高度

时间:2015-01-07 10:51:15

标签: html css

我有这样的代码:

<td width="10">
<div style="border-left: 1px dashed #cccccc;width:10px;height:100%;"></div>
</td>

我还有其他两个带有元素的列,它们的高度可能很大 我想将div设置为最大高度,如bigest列中所示。身高:100%不起作用。 怎么做?

2 个答案:

答案 0 :(得分:1)

我无法使用纯html / css。但我已经使用了几行 javascript代码

window.onload = function() {
    var h  = document.getElementById('maintable').offsetHeight;
    var el = document.getElementById('resizeme');
    el.style.height = h+'px';
}

<强> HTML

<table id="maintable">
    <tr>
        <td></td>
        <td><div id="resizeme"></div></td>
        <td>one<br/>two<br/>three<br/>four<br/>five<br/></td>
    </tr>
</table>

<强> CSS

#resizeme {border: 1px solid blue;}
table {border-collapse: collapse;}
table tr td {vertical-align: top; border: 1px solid; padding: 5px;}

基本上,一切都取决于你的最终目标。可能你只能使用html / css解决你的问题...... 另外,尽量不要在html代码中使用CSS样式......

答案 1 :(得分:0)

<td width="10px">
<div style="border-left: 1px dashed #cccccc;width:inherit;display:table"></div>
</td>

希望这会有所帮助