I'm trying to build a simple grid of div
s: (live demo here)
HTML:
<div class="board"></div>
JS:
$(function() {
var boardHTML = '';
for (var r = 0; r < 2; r++) {
var row = '<div class="row">';
for (var c = 0; c < 5; c++) {
row += '<div class="cell"></div>';
}
row += '</div>';
boardHTML += row;
}
$('.board').append(boardHTML);
});
CSS:
.cell {
width: 30px;
height: 30px;
outline: 1px solid black;
display: inline-block;
}
.row {
background-color: red;
}
But, the result looks like this:
QUESTION: What causes this space between rows?
One possible solution is:
.row {
height: 30px;
}
Also, to get rid of the extra space on the right hand side, I could add:
.board {
width: 150px; /* 5 * 30px */
}
However, I wonder if there is a better solution which doesn't require setting the width/height in pixels.
Do you have any other ideas?