【发布时间】:2016-09-28 20:06:10
【问题描述】:
与“Creating a html table with dynamically expanding number of columns to fit screen size”基本相同的问题。
但是,我正在寻找一个没有第三方库的纯 Javascript 解决方案。我无权访问它们。
起点如下:
<div id="icons"></div>
#icons {
display: table;
width: 100%;
}
.iconBody { display: table-row-group; } /* May not be necessary to solution */
.iconRow { display: table-row; }
.iconCell { display: table-cell; }
function loadValues() {
// other stuff
var iconTable = document.getElementById("icons");
// TODO following lines are editable to suit the solution as necessary
for (var i = 0; i < icons.length; ++i) {
addIcon(iconTable, icons[i]);
}
}
function addIcon(iconTable, icon) {
// TODO add solution here
// Row addition example
var row = document.createElement("DIV");
row.className = "iconRow";
iconTable.appendChild(row);
// Cell addition example
var cell = document.createElement("DIV");
cell.className = "iconCell";
row.appendChild(cell);
// Icon addition example
var iconImg = document.createElement("IMG");
var iconImg.src = icon.srcPath;
iconImg.addEventListener("click", someFunction);
cell.appendChild(iconImg) ;
}
此表没有标题/标签,只有一组图标供用户从中选择一个。图标彼此具有相同的尺寸,尽管图标存储在服务器端,因此我可能会或可能无法获得它们的尺寸值。但是,这些值永远不会改变。显示页面的应用程序面板可以调整大小,因此我希望此表必须根据面板的当前宽度适合的列数而不会水平溢出。
应用程序使用 IE 11.212.10586.0 显示网页。
【问题讨论】:
标签: javascript html css internet-explorer css-tables