I am trying to create a grid using Javascript. I have it created so that the rows are properly aligned within the container, however there is a 4px whitespace being added underneath every row that I need to get rid of so that there is no whitespace within the grid. Here's my code:
function grid(num) {
var container = document.createElement("div");
container.id = "main";
container.className = "container";
document.body.appendChild(container);
var main = document.getElementById('main');
for (var i = 1; i <= num; i++) {
var row = document.createElement('div');
row.className = "row";
row.id = "row" + i;
main.appendChild(row);
var currentRow = document.getElementById('row' + i);
for (var r = 1; r <= num; r++) {
var box = document.createElement('div');
box.className = 'box';
box.style.height = ((800 - (num * 2)) / num) + 'px';
box.style.width = ((800 - (num * 2)) / num) + 'px';
currentRow.appendChild(box);
}
}
}
window.onload = grid(16);
.container {
border: solid #000;
height: 800px;
width: 800px;
}
.box {
border: 1px solid #000;
display: inline-block;
}