流体元素和溢出问题
这是我碰到的一个树桩。
我正在设计一个……东西。 它根据浏览器窗口调整自身大小,顶部有一些控件,底部附近有一个相当大的列表。 无论如何,它基本上是一个根据浏览器窗口调整大小的表格单元格,其大小是文档大小 - 高度 130px,文档大小 - 宽度 50px。 我想要它做的是,当该单元格内的内容列表比单元格大时,它会使用 css 的溢出:auto 变得滚动。
问题是我无法让它做到这一点,只能使整个文档滚动。 目前,该单元格除了 valign:top 之外没有任何属性,并且其中有一个 div(列表元素写入其中),并且它设置为 Overflow:auto。 但是,当列表变得太长时,它只会放大整个文档。
我不想给它一个静态大小,因为它的大小与页面有关。
有任何想法吗?
谢谢! -戴夫
So here's a stump I've hit.
I'm designing a... Thing. It sizes itself to the browser window, with some controls at the top and a rather large list near the bottom. Anyways, it's basically a table cell that sizes with the browser window, whos size is the document size - 130px in height, and document size - 50px in width. What I want it to do, is when the list of stuff inside that cell is bigger then the cell, it to become scrolly using css's overflow: auto.
The problem, is that I can't get it to do that, only make the entire document scrolly. Currently, the cell has no properties aside from valign:top, and it has a single div in it (to which the list elements are written), and it's set to overflow:auto. However, it's just scales up the entire document when the list becomes to long.
I don't want to give it a static size since it sizes with the page.
Any ideas?
Thanks!
-Dave
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我不确定我理解是否正确,但这里的尝试可能会给您带来想法。
I'm not sure I understand correctly, but here's a try that may give you ideas.
buti-oxa 的解决方案非常好,但在 Internet Explorer 中不起作用。
对于跨浏览器解决方案,您需要为包含列表的 div 分配固定高度。 您不能仅使用 css 来完成此操作,因为要分配的高度取决于浏览器窗口的高度。
但是您可以使用一个简单的 javascript 函数来动态地将高度分配给 div。
下面是一个使用 jQuery 的示例:
您应该在加载页面以及用户调整窗口大小时调用此函数:
您可以在我发布的演示页面中看到此函数的实际效果(调整窗口大小以进行测试):
http://www.meiaweb.com/test/BMS_DM_NI/
The solution of buti-oxa is very nice, but doesn't work in Internet Explorer.
For a cross-browser solution, you need to assign a fixed height to the div that contains the list. You can't do it using only css, because the height to assign depends from the height of the browser window.
But you can use a simple javascript function to dinamically assign the height to the div.
Here is an example, using jQuery:
You should call this function when the page is loaded and when the user resizes the window:
You can see this in action in this demo page I posted (resize window to test):
http://www.meiaweb.com/test/BMS_DM_NI/
如果我没记错并且您的内容只是文本,您可以添加换行属性,尽管这在 Firefox 中不起作用,但您可以将 wbr 添加到您的文本中
if I m not wrong and your content is only text you can add wrap property although this dosen't work in firefox u can add wbr to your text
我认为你应该考虑流体布局设计模式。
几个提示:
I think you should consider fluid layout design patterns.
Couple of tips:
我认为 iFrame 会有所帮助。 将您的“事物”放入基本 URL,然后使用另一个带有 iFrame 的页面来加载它。 当“东西”的尺寸变得疯狂时,滚动条就会出现,但您的外页不会受到影响。
老式框架也应该可以使用,但 iFrame 更有趣......
I think an iFrame would help. Put your 'thing' into a base URL, and then use another page with an iFrame to load it. As the 'thing' goes crazy in size, the scroll bars appear, but your outer page is not effected.
An old fashion frame should work too, but iFrames are just more fun ....