Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You could build it with CSS floats, e.g if the squares are 20x20px:</p> <pre><code>&lt;style type="text/css"&gt; div.container { width: Xpx; /* 20px [square box width]+1px [border width of each square])) * number of squares */ height: Xpx; /* similar to above] */ border: solid black; border-width: 1px 0px 0px 1px;} /* North East South West */ div.square { float: left; width: 20px; height: 20px; border: solid black; border-width: 0px 1px 1px 0px;} div.row { clear: both;} &lt;/style&gt; &lt;div class="container"&gt; &lt;div class="row"&gt; &lt;div class="square"&gt; &lt;/div&gt; ... &lt;/div&gt; ... &lt;/div&gt; </code></pre> <p>Remember to use IE with a valid doctype <a href="http://htmlhelp.com/tools/validator/doctype.html" rel="nofollow noreferrer">http://htmlhelp.com/tools/validator/doctype.html</a> or to use box model hacks in quirks mode [<a href="http://tantek.com/CSS/Examples/boxmodelhack.html]" rel="nofollow noreferrer">http://tantek.com/CSS/Examples/boxmodelhack.html]</a>.</p> <p>You could probably make the above take up less if you use IDs instead of classes and use single letters in the CSS.</p> <p>What's <em>fastest</em> usually depends wildly on the browser though, e.g. I wouldn't be surprised if IE performs better with tables, while other browsers perform better with relative DIVs/floats.</p> <p>(I haven't tested the above, but something similar should work.)</p> <p>You could then convert the above to JavaScript to reduce page load times, e.g:</p> <pre><code>function GenHTML(NumRows, NumCols) { var LRows = [] for (var x=0; x&lt;NumRows; x++) { var LCols = [] for (var y=0; y&lt;NumCols; y++) { var HTML = '&lt;div class="square"&gt;&lt;/div&gt;' LCols.push(HTML)} LRows.push('&lt;div class="row"&gt;'+ LCols.join('') +'&lt;/div&gt;')} return LRows.join('')} function SetHTML(NumRows, NumCols) { document.getElementById('container').innerHTML = GenHTML(NumRows, NumCols)} </code></pre>
 

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