Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
478 views
in Technique[技术] by (71.8m points)

css - float variable height containers

So i have x amount of "blocks" that I want to float left.. Like this :

A B C D

E F G H

BUT, if B is twice as long as the rest, for example, there would be white space between A & E, C & G, D & H.

How can I avoid that and just have all the containers float to the left and then fit in nicely without excess white space in between ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

CSS cannot handle this in the general case.

If there are a fixed number of columns, you can cheat and do this: http://jsfiddle.net/suaaK/11/

Otherwise:

See this answer for a comparison of the candidate techniques, showing that they don't work:

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

Demos:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...