var grid = document.getElementById("grid");
var size = 50;
for (var y = 0; y < size; y++) {
var currentRow = grid.insertRow(0);
for (var x = 0; x < size; x++) {
var currentCell = currentRow.insertCell(-1);
currentCell.style.height = currentCell.style.width = `calc(100vh / ${size})`;
currentCell.style.backgroundColor = (x+y)%2 == 0 ? "Blue" : "Red";
}
}
body {
margin: 0;
}
table#grid {
border-collapse: collapse;
height: 100%;
}
<html>
<body>
<table id="grid" align="center"></table>
</body>
</html>
What I need is a table that fits screen height and has squared cells. I tried almost everything, the best result I got using hidden images. The cells are almost squared, not enough for my needs though. Of course I don't want to use any absolute spacing. In fact I would like to do it without images too, just plain CSS/JavaScript. The size of the table will just be known at runtime, but let's assume it's 2 by 2:
<table>
<tr>
<td><img src='placeholder.png'></td>
<td><img src='placeholder.png'></td>
</tr>
<tr>
<td><img src='placeholder.png'></td>
<td><img src='placeholder.png'></td>
</tr>
</table>
And in the CSS
table {
height: 100%;
}
img {
height: 100%;
width: auto;
visibility: hidden
}
Any ideas (that are not too over-sophisticated) are very much appreciated.