Html 处理表中的溢出

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1471210/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 00:55:30  来源:igfitidea点击:

Handling overflow in tables

htmlcssoverflowcss-tables

提问by Dorjan

If I have a table like this very very simple example:

如果我有一个像这个非常简单的例子的表:

table {
    table-layout:fixed;
    width:300px;
}

.td1 {
    width:100px;
}
.td2 {
    width:200px;
}

and in one of my .td2contains an image that is, lets say, 300pxin width. I would like to show scroll bars to allow users to scroll to see it all. However I don't think this is possible, is it?

并且在我的.td2其中一个包含一个图像,比如说,300pxwidth. 我想显示滚动条以允许用户滚动查看所有内容。但是我不认为这是可能的,是吗?

So my questions are:

所以我的问题是:

  1. Are there any other options apart from hiddenfor handling overflow in tables?

  2. Is it possible to show scroll-bars only when content pushes beyond a set width? (I swear I've seen it in some forum software but I can't remember which one)

  1. 除了hidden处理表中的溢出之外,还有其他选择吗?

  2. 是否可以仅在内容超出设定宽度时显示滚动条?(我发誓我在一些论坛软件中看到过,但我不记得是哪个)

回答by rahul

What about

关于什么

overflow: auto

Content is clipped and scrolling is added only when necessary.

仅在必要时剪辑内容并添加滚动。

Put the image inside a div in the table cell and make the width and height of the div to be 100% of the td and style it to overflow: auto

将图像放在表格单元格的 div 中,并使 div 的宽度和高度为 td 的 100% 并将其样式设置为溢出:自动

<style>
.test { width: 100%; height: 100%; overflow: auto; } 
</style>

<td>
<div class="test">
your image
</div>
</td>