Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml" &gt; &lt;head&gt; &lt;title&gt;Untitled Page&lt;/title&gt; &lt;style type="text/css"&gt; .xstyle{display:block; float:left; padding-left:2px; padding-right:2px; border:1px solid black;} .spacer{display:block; float:left;} &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="words" style="width:700px;height:300px;border:1px solid red"&gt; &lt;/div&gt; &lt;script type="text/javascript"&gt; var words = ["mine", "minute", "mist", "mixed", "money", "monkey", "month", "moon", "morning", "mother", "motion", "mountain", "mouth", "move", "much", "muscle", "music", "nail", "name", "narrow", "nation", "natural", "near", "necessary", "neck", "need", "needle", "nerve", "net", "new", "news", "night", "big big big big big big big big big word"]; ( function fillWords() { words.sort ( function(a, b) { return b.length - a.length; } ); if (!Array.prototype.forEach) Array.prototype.forEach = function(callback, thisObj) { if (typeof (callback) == 'function') { for (var i = 0; i &lt; this.length; i++) callback.call(thisObj, this[i], i, this); } }; if (!Array.prototype.some) Array.prototype.some = function(callback, thisObj) { if (typeof (callback) == 'function') { for (var i = 0; i &lt; this.length; i++) if (callback.call(thisObj, this[i], i, this)) return this[i]; } }; var totalWidth = 0; var firstIndex = 0; var wBox = document.getElementById("words"); var objList = []; function fillSpaces(count) { var space = 700 - totalWidth; var eachSpace = Math.ceil(space / count) + 1; objList.some ( function(sobj, i) { if (i &gt; 0) { var spacer = document.createElement("div"); if (totalWidth + eachSpace &gt; 700) eachSpace = 700 - totalWidth; spacer.className = "spacer"; spacer.style.width = eachSpace + "px"; spacer.style.height = sobj.offsetHeight + "px"; wBox.insertBefore(spacer, sobj); totalWidth += eachSpace; } return totalWidth &gt;= 700; } ); if (totalWidth &lt; 700) { var spacer = document.createElement("span"); spacer.className = "spacer"; spacer.style.width = (700 - totalWidth) + "px"; wBox.insertBefore(spacer, objList[objList.length - 1]); } } words.forEach ( function(item, index) { var obj = document.createElement("a"); obj.href = "#"; obj.className = "xstyle"; obj.innerHTML = item; wBox.appendChild(obj); var ow = obj.offsetWidth; totalWidth += ow; if (totalWidth &gt;= 700) { totalWidth -= ow; fillSpaces(index - firstIndex); objList = [obj]; totalWidth = ow; firstIndex = index; } else { objList.push(obj); } } ); fillSpaces(words.length - firstIndex - 1); } )(); &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </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