CSS流体设计问题
请在这里找到代码: http://jsfiddle.net/yuliantoadi/XQuuT/
你可以看到grid_1和grid_2宽度固定为50px,但grid_2宽度为80%。问题是当我减小包装器宽度时,grid_3 div 会下降。
当我们在不使用 javascript 的情况下减小包装器宽度时,知道如何使 grid_3 保持在顶部吗?
请不要更改 grid_1 和 grid_3 宽度。
please find the code in here: http://jsfiddle.net/yuliantoadi/XQuuT/
you could see grid_1 and grid_2 width are fixed 50px, but grid_2 width is 80%. the problem is when i decrease the wrapper width, the grid_3 div goes down.
any idea how to make the grid_3 stay in the top when we decrease the wrapper width without use javascript?
please don't change the grid_1 and grid_3 width.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
解决方案 CSS:
解决方案 HTML:
请注意,HTML 首先设置左浮动,然后是右浮动,然后是未浮动的内容,因此在浮动元素之间呈现。此外,内容没有定义宽度,因此它将填充空间。
Solution CSS:
Solution HTML:
Note that the HTML sets up the left float first, then the right float, THEN the content, which is unfloated and thus renders between the floated elements. Also the content has no width defined, so it will fill the space.
该问题是由于混合使用流动元素宽度和固定元素宽度而引起的。
假设你的包装器是 1000px 宽 - grid_1 是 50px,grid_3 是 50px,grid_2 是 80%,或 800px,这很好,一切都会很好地排列
如果包装器是 400px 宽,grid_1 和 grid_3 仍然是 50px,grid_2 是 320px ( 400px的80%),这意味着三个元素无法容纳并排,因为 50+50+320 = 420px
本质上,只要你的包装器宽度小于 500px,你就会让 grid_3 包装到一个新行。
如果不确切知道您想要实现什么目标,就很难提供解决方案
The problem is caused by using a mix of fluid and fixed element widths.
Say your wrapper is 1000px wide - grid_1 is 50px, grid_3 is 50px and grid_2 is 80%, or 800px, which is fine, everything will line up nicely
If the wrapper is 400px wide, grid_1 and grid_3 are still 50px, grid_2 is 320px (80% of 400px), which means the three elements can't fit side-by-side, since 50+50+320 = 420px
Essentially, as soon as your wrapper is less than 500px wide you'll have grid_3 wrapping to a new line.
Without knowing exactly what you're trying to achieve, it's hard to offer a solution
我认为如果网格 1 和网格 1 是不可能的3.固定宽度。为了避免网格 3 下降,您可以设置其最小宽度。
I think that's not possible if grid 1 & 3 fixed width. To avoid grid 3 go down, you can set its min-width.
还有一种使用负边距的替代方法。 HTML 是相同的,您向左侧和右侧元素添加负边距,并向中心添加正边距,从而使中心
div
一直延伸到元素的外边缘。侧面div
。There is also an alternative method using negative margins. The HTML is the same, and you add negative margins to the left and right elements, and add positive margins to the center, allowing you to have the center
div
stretch all the way to the outside edges of the sidediv
s.