Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is a solution, quite a bit of adjustment was made to your original to get it to work, as you will probably notice.</p> <p>CSS</p> <pre><code>div.rounded { width: 100%; border-style: solid; border-width: 1px; border-radius: 5px; } label { display: block; } input { display: block; } #previewTable { width: 100%; } </code></pre> <p>HTML</p> <pre><code>&lt;div id="imagesDiv" class="rounded"&gt; &lt;label for="chooseFiles"&gt;Add Images&lt;/label&gt; &lt;input type="file" id="chooseFiles" multiple="multiple" /&gt; &lt;table id="previewTable"&gt; &lt;thead id="columns"&gt;&lt;/thead&gt; &lt;tbody id="previews"&gt;&lt;/tbody&gt; &lt;/table&gt; &lt;/div&gt; </code></pre> <p>Javascript</p> <pre><code>(function (global) { var imagesPerRow = 3, chooseFiles, columns, previews; function PreviewImages() { var row; Array.prototype.forEach.call(chooseFiles.files, function (file, index) { var cindex = index % imagesPerRow, oFReader = new FileReader(), cell, image; if (cindex === 0) { row = previews.insertRow(Math.ceil(index / imagesPerRow)); } image = document.createElement("img"); image.id = "img_" + index; image.style.width = "100%"; image.style.height = "auto"; cell = row.insertCell(cindex); cell.appendChild(image); oFReader.addEventListener("load", function assignImageSrc(evt) { image.src = evt.target.result; this.removeEventListener("load", assignImageSrc); }, false); oFReader.readAsDataURL(file); }); } global.addEventListener("load", function windowLoadHandler() { global.removeEventListener("load", windowLoadHandler); chooseFiles = document.getElementById("chooseFiles"); columns = document.getElementById("columns"); previews = document.getElementById("previews"); var row = columns.insertRow(-1), header, i; for (i = 0; i &lt; imagesPerRow; i += 1) { header = row.insertCell(-1); header.style.width = (100 / imagesPerRow) + "%"; } chooseFiles.addEventListener("change", PreviewImages, false); }, false); }(window)); </code></pre> <p>On <a href="http://jsfiddle.net/Xotic750/6cgTj/">jsfiddle</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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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