Note that there are some explanatory texts on larger screens.

plurals
  1. POCSS float, clear a "row" of floating elements
    primarykey
    data
    text
    <p>I want to create a "scorecard" grid to output some data. If the data in each div.item is all the same height, then a simple float left on each div.item gives a nice even layout which scales up and down nicely depending on browser size. </p> <p>If the data however is variable, a different number of lines in each div, then the way elements float gives an uneven and messy output. See code sample below. If you create a page with the below, resize the browser to about 800px wide so that box 1, 2, and 3 create a "row" on top, followed by 4, 5 and 6. How do I get 7 to drop down to the next line so it creates a row along with 8 and 9?</p> <p>Obviously if you resize the browser so that 4 divs appear in each row, number 9 is the element I want to break down below 5. Is there something obvious I am missing or do I need to use some Javascript to achieve this?</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-css lang-css prettyprint-override"><code>div.item{ float:left; width:220px; background-color:#DBDBDB; margin:8px; } h1, p{ padding:4px; margin:0; }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class='item'&gt; &lt;h1&gt;1&lt;/h1&gt; &lt;p&gt;Content&lt;/p&gt; &lt;p&gt;Content&lt;/p&gt; &lt;p&gt;Content&lt;/p&gt; &lt;/div&gt; &lt;div class='item'&gt; &lt;h1&gt;2&lt;/h1&gt; &lt;p&gt;Content&lt;/p&gt; &lt;p&gt;Content&lt;/p&gt; &lt;p&gt;Content&lt;/p&gt; &lt;/div&gt; &lt;div class='item'&gt; &lt;h1&gt;3&lt;/h1&gt; &lt;p&gt;Content&lt;/p&gt; &lt;p&gt;Content&lt;/p&gt; &lt;p&gt;Content&lt;/p&gt; &lt;/div&gt;</code></pre> </div> </div> </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload