如何强制 div 拉伸以适合其内容而不是制作滚动条?
我的应用程序中有一个表格可能会增长到荒谬的高度,因此我在它周围添加了一个包装器 div
并设置 overflow-y: auto
来获取滚动条。不幸的是,这阻止了 div 拉伸其宽度。现在它有高度和宽度的滚动条。设置overflow-x:visible甚至不会影响结果。我需要拉伸宽度,因为内容的宽度是可变的。
小提琴来说明问题: http://jsfiddle.net/SG8T9/3
感谢您的帮助
I had a table in my application that could grow to ridiculous heights, so I added a wrapper div
around it and set overflow-y: auto
to get scrollbars. This unfortunately stopped the div from stretching it's width. Now it has scrollbars for both height and width. Setting overflow-x: visible
doesn't even affect the result. I need the width to stretch since the content is of variable width.
Fiddle to illustrate the problem: http://jsfiddle.net/SG8T9/3
Thanks for any help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定这是否是你的意思,但看看这里
http://www.brunildo.org/test/Overflowxy2.html
该页面的
所以
overflow-x:visible
变为overflow-x:auto
。也许您可以使容器足够宽以容纳内容物,这样它就不必溢出。
I'm not sure if this is what you mean but take a look here
http://www.brunildo.org/test/Overflowxy2.html
from that page:
so
overflow-x: visible
becomesoverflow-x: auto
.maybe you can make the container wide enough to hold the content, so it doesn't have to overflow.
你不能为你的div定义宽度,否则无论overflow-x设置如何,它都不会溢出该宽度。相反,使用 min-width 和 max-width 来设置扩展值,然后
overflow-x:visible;
应该可以正常工作。这是一个小提琴: http://jsfiddle.net/shanethehat/SG8T9/
请注意,定义的 max-宽度必须至少与内容的宽度加上垂直滚动条的宽度一样大。
You must not define a width for your div, otherwise it will not overflow that width regardless of the overflow-x setting. Instead use min-width and max-width to set expansion values, then
overflow-x:visible;
should work fine.Here's a fiddle: http://jsfiddle.net/shanethehat/SG8T9/
Note that the defined max-width must be at least as large as the width of the content plus the width of the vertical scrollbar.