Note that there are some explanatory texts on larger screens.

plurals
  1. POLayout html grid without widows (responsive)
    primarykey
    data
    text
    <p>edit just to clarify what I want: my current algorithm is a little basic and makes too many rows. I want to use as little rows as possible without adding widows.</p> <p>I am trying to layout my products without having one or two widows in the bottom row. I made a small prototype but it doesn't always work like expected (it should always try to use the maximum width while reducing the chance of having only 1 or 2 squares on the bottom row). <a href="http://jsfiddle.net/ffuUD/1/" rel="nofollow">jsfiddle.net/ffuUD</a></p> <pre><code>function format(val) { var decimal = val.toString().substr(val.toString().indexOf(".") + 1, 1) if ((val &lt;= 4 || (decimal &gt;= 6 || isInt(val))) &amp;&amp; $('.product').outerWidth(true) * val &lt; $('body').width() ) { return true; } else { return false; } } function recalculate() { for (var i = 1; i &lt; 6; i++) { if (format($('.product').length/i)) { $('.products').width($('.product').outerWidth(true) * $('.product').length/i); break; } } } </code></pre> <p>There should be a way to reduce widows and layout the divs in the most optimal way possible. Any tips?</p> <p>expected results (try expanding the width of the jsfiddle window): </p> <p>7 has a widow when the window isn't very large. the 3 rows should be 2.</p> <p>11,14,17,20 should be in 3 rows instead of 4</p> <p>13 is a hard one too but not exactly sure.</p> <p><strong>Update:</strong> If anyone knows a better way please answer: <a href="http://jsfiddle.net/ffuUD/3/" rel="nofollow">jsfiddle.net/ffuUD/3</a></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.
    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