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
Handling overflow in 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 .td2
contains an image that is, lets say, 300px
in 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
其中一个包含一个图像,比如说,300px
在width
. 我想显示滚动条以允许用户滚动查看所有内容。但是我不认为这是可能的,是吗?
So my questions are:
所以我的问题是:
Are there any other options apart from
hidden
for handling overflow in tables?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)
除了
hidden
处理表中的溢出之外,还有其他选择吗?是否可以仅在内容超出设定宽度时显示滚动条?(我发誓我在一些论坛软件中看到过,但我不记得是哪个)
回答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>