Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flow layout with collapsible divs, that maintains row structure

Tags:

html

css

I have a fluid layout made with collapsible divs. When they collapse, they leave an empty space underneath, which is automatically filled by the next div (they all have float: left). This however does not look good and I would like to maintain the "row structure" without loosing the ability to move the divs around (when the window gets smaller). JSFiddle here.

Problem description

CSS snippet:

.clickable {
     border: 1px dotted black;
     width: 200px;
     float: left;
     height:50px;
     margin-right:20px;
     margin-bottom:20px;
}

HTML snippet:

<html>
<head><title>Layout test</title></head>
<body>
   <div class="clickable">&nbsp;1&nbsp;</div>
   <div class="clickable">&nbsp;2&nbsp;</div>
   <div class="clickable">&nbsp;3&nbsp;</div>
   <div class="clickable">&nbsp;4&nbsp;</div>
   <div class="clickable">&nbsp;5&nbsp;</div>
   <div class="clickable">&nbsp;6&nbsp;</div>
</body>
<html>

Is there a pure CSS solution? I would like not to mess with JavaScript. I know I can dynamically determine the number of columns and then wrap them into "rows", but I'm not willing to use this solution yet.

like image 653
Andrei V Avatar asked Nov 07 '13 14:11

Andrei V


1 Answers

Change your float: left to display: inline-block. That's the only change I made to your fiddle, and seems to give the effect you're looking for.

http://jsfiddle.net/GLf7m/2/

like image 192
Daniel Attfield Avatar answered Nov 15 '22 08:11

Daniel Attfield