Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Suppose the HTML page generated contains:</p> <pre><code>&lt;ul&gt; &lt;li class="item1"&gt;A&lt;/li&gt; &lt;li class="item2"&gt;B&lt;/li&gt; &lt;li class="item3"&gt;C&lt;/li&gt; &lt;li class="item4"&gt;D&lt;/li&gt; &lt;li class="item5"&gt;E&lt;/li&gt; &lt;li class="item6"&gt;F&lt;/li&gt; &lt;li class="item7"&gt;G&lt;/li&gt; &lt;li class="item8"&gt;H&lt;/li&gt; &lt;li class="item9"&gt;I&lt;/li&gt; &lt;li class="item10"&gt;J&lt;/li&gt; &lt;li class="item11"&gt;K&lt;/li&gt; &lt;li class="item12"&gt;L&lt;/li&gt; &lt;li class="item13"&gt;M&lt;/li&gt; &lt;li class="item14"&gt;N&lt;/li&gt; &lt;li class="item15"&gt;O&lt;/li&gt; &lt;/ul&gt; </code></pre> <p>You may now use JavaScript to generate the required CSS as follows:</p> <pre><code>/* unorderedList: the HTML ul element columnSize: the number of items per column columnGap: the distance between 2 columns in ems offset: the offset of the first column in ems */ function generateMultiColumnLayout(unorderedList, columnSize, columnGap, offset) { var items = unorderedList.getElementsByTagName("li"); for (var i = 0, l = items.length; l--; i++) { var itemStyle = items[i].style; itemStyle.lineHeight = "1.2em"; if (!i &amp;&amp; i % columnSize) { // old column itemStyle.marginLeft = offset + "em"; } else { // start of new column offset += columnGap; itemStyle.marginLeft = offset + "em"; itemStyle.marginTop = -columnSize + "em"; } } } window.onload = function () { var items = document.getElementsByClassName("item1"); for (var i = 0, l = items.length; l--; i++) { generateMultiColumnLayout(items[i].parent, 8, 10, 5); } }; </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