[英]Prevent elements from wrapping when resizing the window
How can I prevent my squares from wrapping when resizing the window? 在调整窗口大小时,如何防止正方形包裹?
I want the squares to stay at their positions, but every time I resize the window, they get pushed down and are hidden. 我希望方块保持在他们的位置,但每次我调整窗口大小时,它们都被推下并隐藏起来。
This example is currently working, but the solution, which makes this possible, is just ridiculous. 这个例子目前正在运行,但是使这成为可能的解决方案是荒谬的。
Is there a "cleaner" way or how can I make it look more professional? 是否有“更清洁”的方式或如何让它看起来更专业?
My JSFiddle Example 我的JSFiddle示例
.content {
width: 100000000px;
}
Remove position:absolute
and overflow:hidden
from the parent element. 删除
position:absolute
和overflow:hidden
从父元素overflow:hidden
。
Since the elements are inline-block
, you could use white-space:nowrap
to prevent them from wrapping. 由于元素是
inline-block
,因此可以使用white-space:nowrap
来防止它们被包装。 If that's not the desired effect, just remove it though. 如果这不是预期的效果,请删除它。
#container {
width: 100%;
height: 100px;
white-space:nowrap;
}
.square {
display: inline-block;
width: 100px;
height: 100px;
}
http://jsfiddle.net/CLErY/2/ http://jsfiddle.net/CLErY/2/
/* The following rule can be romoved, is just to give a smooth overflow hidden visibility */
.content {
width: 200%; /* Always bigger than the real value, so 200% is the double and it should work. */
}
.content should have at least the size of the whole element plus the size of one children (100px), so 200% is the double and it should work. .content应该至少具有整个元素的大小加上一个孩子的大小(100px),所以200%是双倍的,它应该工作。
In case we have 4 squares the size should be (width x 4 + width) in case the width of the square is 100 the result is 500px. 如果我们有4个正方形,则尺寸应为(宽度x 4 +宽度),如果正方形的宽度为100,则结果为500px。
Also this is to give a smoother overflow dissapear but not necesary. 这也是为了给出更平滑的溢出消除但不是必要的。
Hope it helps. 希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.