Currently, I am working on a project that requires stacking multiple buttons on top of each other without any gaps in between. Here is my existing code:
This is the desired outcome:
Can this be achieved using CSS?
The function I am currently using accepts a height and width to create a grid of buttons.
function createBoard (height, width)
{
for (let h = 0; h < height; h++)
{
for (let w = 0; w < width; w++)
{
let button = document.createElement('button');
button.setAttribute('class', 'pixel');
document.body.appendChild(button)
if (w == width - 1)
{
let br = document.createElement('br');
document.body.appendChild(br)
}
}
}
}
createBoard(5,10);
.pixel {
margin:0;
background-color: rgb(31, 31, 31);
padding: 10px;
display:inline-block;
border: none;
}
.pixel:hover {
background-color: rgb(73, 73, 73);
}