CSS动态宽度大于100%
我有一个父容器,其中包含浮动项目列表。当添加新的浮动项时,父容器确实会很好地向右扩展。
但是,当我添加更多项目并且这些项目靠近窗口右侧时,新项目只会跳到新行。 相反,我希望它继续向右扩展,使我的父容器大于 100%。
是否可以将容器宽度定义为 max-width:Infinite; 之类的值?
为了回答我自己的问题,我知道我只能将最大宽度设置为 5000% 或其他值,但我只是想知道是否有更好的解决方案。我觉得页面的高度是max-width:infinite有点奇怪;并且页面的宽度不能有相同的行为。
也许这只是一个愚蠢的问题,但我还是问了:P。
I have a parent container that holds a list of floated items. The parent container does nicely expand to the right when new floated items are added.
But as I add more items and the items come near the right side of the window the new item just jumps to a new row.
Instead, I want it to keep expanding to the right, making my parent container larger than 100%.
Is it possible to define a container width to be something like max-width: infinite;?
To answer my own question I know I just can make a max-width of 5000% or something, but I was just wondering if there is a better solution. I think it's a kind of strange that the height of a page is max-width: infinite; and the width of a page cannot have the same behavior.
Maybe this is just a silly question, but I ask it anyway :P.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我所知,如果不使用 Javascript 来计算浮动的宽度,您就无法可靠地执行此跨浏览器操作。
然后,您可以在上面放置一个“包装器”div,以确保隐藏浮动宽度可能为 5000px 的事实。使用overflow-x滚动会让你的div看起来在不断增长。
我认为这是由于盒子模型造成的,据我所知,没有计算出宽度的容器会变得越来越大。在 DOM 层次结构(想想 body/html)中,您总是会遇到具有固定宽度的父块元素。
As far as i'm aware, you can not reliably do this cross-browser without using Javascript to calculate the widths of your floats.
Then, you can have a "wrapper" div around the above, that ensures that hides the fact your floats may be 5000px in width. Using overflow-x to scroll will give the appearance that your div is constantly growing.
I think this is due to the box model, as far as i'm aware there is no container that gets bigger and bigger and bigger, without a calculated width. You will always hit a parent block element along the way up the DOM hierarchy (think body/html) with a fixed width.
我认为
overflow:visible
应该可以解决问题。I think that
overflow:visible
should do the trick.