简体   繁体   English

CSS或Javascript DIV对齐

[英]CSS or Javascript DIV align

I have website that where the php code generates all the products on the same page. 我有一个网站,其中php代码在同一页面上生成所有产品。

So far i get something like this. 到目前为止,我得到这样的东西。

http://ratecleveland.com/irregular_height_columns.jpg http://ratecleveland.com/irregular_height_columns.jpg

however i am trying to get something like this. 但是我试图得到这样的东西。

http://ratecleveland.com/new.jpg http://ratecleveland.com/new.jpg

any idea if this can be done in css. 任何想法,如果可以在CSS中完成。 or if no, is there a javascript examle. 否则,是否存在JavaScript示例。

thank you for the help 感谢您的帮助

jQuery Masonry: http//masonry.desandro.com/

Here's a fiddle, use display:inline-block; 这是一个小提琴,使用display:inline-block; with the ?display hack 显示黑客

http://jsfiddle.net/qW3TV/ http://jsfiddle.net/qW3TV/

No javascript is necessary. 不需要javascript。

Looks like all of the divs are the same width. 看起来所有div的宽度相同。 Why not just create containing column divs around the ones you want to stack? 为什么不只围绕要堆叠的列创建包含div的列?

<div class="col1">
    <div class="a"></div>
    <div class="e"></div>
    <div class="i"></div>
</div>
<div class="col2">
    <div class="b"></div>
    <div class="f"></div>
    <div class="k"></div>
</div>
<div class="col3">
    <div class="c"></div>
    <div class="g"></div>
    <div class="l"></div>
</div>
<div class="col4">
    <div class="d"></div>
    <div class="h"></div>
    <div class="m"></div>
</div>

Float each column left and your interior div's, which appear to already have specified width and height, will fall into place. 浮动左列,您的内部div(似乎已经具有指定的宽度和高度)将落入适当位置。 You can even give the columns the same class, since they will just be floated left containers. 您甚至可以给这些列提供相同的类,因为它们只会被浮动在左边的容器中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM