简体   繁体   English

防止单元格扩展表格高度

[英]Prevent a cell from expanding table height

I'm attempting to make an image take all the remaining width available for a table and span the entire height of a table without extending it any further, with overflow:auto to scroll if there's not enough height.我正在尝试使图像占用表格的所有剩余宽度并跨越表格的整个高度而不进一步扩展它,如果高度不足,则使用 overflow:auto 滚动。

The width bit is easy, but no matter what I do the table cell containing the image will extend the height of the table.宽度位很容易,但无论我做什么,包含图像的表格单元格都会扩展表格的高度。 Is there a way to prevent this, short of explicitly setting the image's height?除了明确设置图像的高度之外,有没有办法防止这种情况发生?

Thus far the solutions I've found differ on browser, so aren't ideal.到目前为止,我发现的解决方案在浏览器上有所不同,因此并不理想。 You could render different markup based on the client.您可以根据客户端呈现不同的标记。 (But still looking for a more universal answer.) (但仍在寻找更通用的答案。)

Updated again for the most universal solution so far:再次更新目前最通用的解决方案:

<style>
    div.ImageBlock
    {
        height:100%;
        width:100%;
        left:0px;
        top:0px;
        overflow:auto;
    }
    div.IE_CompatMode
    {
        position:absolute;
    }
</style>

Either works in Chrome, and the IE_CompatMode has to be added when IE has compatibility mode On.要么在 Chrome 中工作,当 IE 具有兼容模式时,必须添加 IE_CompatMode。

<td rowspan="2" style="position:relative;">
    <div class="ImageBlock [conditional:]IE_CompatMode">
        <img src="Images/Jellyfish.jpg" style="position:absolute; top:0px; left:0px;" />
    </div>
</td>

And nothing (that I've yet tried) works in Firefox.在 Firefox 中没有任何东西(我已经尝试过)起作用。

You would have to use a wrapper element around the content to restrict the height.您将不得不在内容周围使用包装元素来限制高度。

<table>
    <tr>
        <td><div class="overflow">This is short.</div></td>        
        <td><div class="overflow">This is longer.</div></td>   
        <td><div class="overflow">This is really long and repeated. This is really long and repeated.</div></td>           
    </tr>
</table>

.overflow {
    max-height:40px;
    overflow:hidden;
}

var tableHeight = $('table').height();
$('.overflow').css('height',tableHeight + 'px');

Could always give the image a percentage eg height="100%" that should make it the full size of the cell that it is in but would restrict overflow.总是可以给图像一个百分比,例如 height="100%" 应该使它成为它所在单元格的完整大小,但会限制溢出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM