CSS two columns with known children width

前端 未结 3 784
攒了一身酷
攒了一身酷 2020-12-21 13:22

I creating some code for showing box with diffrent heights (height will be from images inside).

In this example works perfectly: http://jsfiddle.net/GSnfG/

.

3条回答
  •  时光说笑
    2020-12-21 14:24

    No, it's not possible to handle this in the general case without JavaScript or a server-side language.

    In some cases, you can add wrapper divs for each separate column, but some combinations of element size will make this look bad, for example: http://jsfiddle.net/suaaK/3/ - in that demo, it would probably be better if Box 6 was under Box 3. The more (and more differently sized) elements you have, the more uneven the columns can become.

    See this answer for a comparison of the candidate techniques, showing that they don't work, and also showing the client-side portion of the solution involving server-side code:

    • CSS Floating Divs At Variable Heights

    If you're willing to use JavaScript+jQuery, you should use jQuery Masonry.

    There's also a raw JavaScript version: Vanilla Masonry

    Demos:

    • http://desandro.com/demo/masonry/docs/filtering.html
    • http://desandro.com/demo/masonry/docs/animating-jquery.html
    • http://desandro.com/demo/masonry/docs/appending.html

提交回复
热议问题