可扩展站点 - 50% 左 50% 右
我有一个简单的页面,如以下链接所示,当您调整浏览器窗口大小时,该页面是可缩放的: http:// Pastehtml.com/view/1eg346q.html
现在工作时,它会向左浮动,当该行中有另一个框的空间时,图片会四处移动。
问题是,当您尝试使浏览器窗口变大时,它会产生大量空白,直到最终有空间容纳新框 - 像这样: http://imageshack.us/photo/my-images/220/scal1.jpg/
有没有办法在两者中传播空白调整大小时网站的大小,所以有点像向左 50%,向右 50%?也许像这样: http://imageshack.us/photo/my-images/ 641/scal2.jpg/
我能想到的唯一方法是将框居中,但我不希望它们始终居中 - 仅当您调整大小时...
如果没有办法做到这一点,请执行此操作您对像我现在这样的缩放以及如何消除白色间距有更好的建议吗?
I have a simple page illustrated on the following link, which is scalable when you resize your browser windwow: http://pastehtml.com/view/1eg346q.html
As it works now, it float's left and when there is room for another box in the row the pictures move around.
The thing is, when you try to make your browserwindow larger, it makes a lot of white space until there is finally room for a new box - like this: http://imageshack.us/photo/my-images/220/scal1.jpg/
Is there any way of spreading the white space in both sites when you resize, so it's kind of like 50% to the left and 50% to the right? Perhaps like this: http://imageshack.us/photo/my-images/641/scal2.jpg/
The only way I can think of is centering the boxes, but I dont want them to be centered all the time - only when you resize...
If there's no way to do this, do you have any better suggestions for scaling like I do now and at the same time on how to get rid of the white spacing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
最简单的方法是将盒子类
float
更改为display: inline-block
然后将所有元素包装在容器中,设置text-align : center;
和margin: 0 auto;
Fiddle: http://jsfiddle.net/4UDxE/
The easiest thing to do would be to change the box class
float
todisplay: inline-block
then wrap all the elements in a container, set atext-align: center;
andmargin: 0 auto;
Fiddle: http://jsfiddle.net/4UDxE/
也许使用 onResize 事件您可以将对齐方式设置为居中并在事件结束后恢复为默认值?
Maybe using the onResize event you can set the alignment to centered and back to default once the event ends?
我认为纯 CSS 是不可能的。
将盒子包装在 div 中(使用
margin:0 auto
和overflow:auto
),然后使用一些 jQuery,我们可以通过演示 http://jsfiddle.net/gaby/8BcQX/
在演示中,我将
.box
的边距更改为左侧10px
和右侧10px
,以实现更准确的居中 >更新评论
里面有一个侧栏:http://jsfiddle .net/gaby/8BcQX/1/(如果你想让它和框对齐,你必须相应地调整它的大小)
在网格之外有一个侧边栏:http://jsfiddle.net/gaby/8BcQX/2/ (对 jquery 进行细微更改适应容器同级的大小)
I do not think that is possible with pure CSS.
Wrapping the boxes in a div (with
margin:0 auto
andoverflow:auto
) and then using some jQuery we can do this withdemo http://jsfiddle.net/gaby/8BcQX/
in the demo i have changed the margin of the
.box
to be10px
left and10px
right for more accurate centeringUpdate for comments
With a side bar in the inside : http://jsfiddle.net/gaby/8BcQX/1/ (you have to size it accordingly if you want it and the boxes to line-up)
With a sidebar outside the grid : http://jsfiddle.net/gaby/8BcQX/2/ (minor changes to the jquery to accommodate for the size of the siblings to the container)