I'm building a game which has the board on the left and the score area on the right. I'd like the individual tiles on the board to remain squares as the browser is expanded. As of now they grow width-wise but they don't grow in height.
Starting set up:
But after making the window wider the tiles become rectangular:
How can I keep the tiles as squares when the browser window is resized?
Here's the relevant part of .html file:
<div class="board">
<div class="square" id="square1">5</div>
(...and 15 more like the above line...)
</div>
<div class="score">
<h1>Score:</h1>
<h2>0</h2>
</div>
JavaScript function that draws the tiles/squares:
function drawSquares() {
for(let i = 1; i < 17; i++) {
const square = document.createElement('div')
square.setAttribute('class', 'square')
square.setAttribute('id', ('square'+i))
square.innerText = randArr[i-1]
board.appendChild(square)
}
}
and my full CSS as I'm not sure which part(s) to change:
body {
display: flex;
}
.board {
height: 370px;
width: 70%;
display: flex;
flex-wrap: wrap;
background-color: rgb(172, 170, 170);
padding: 1%;
margin: 1%;
}
.score {
background-color: rgb(172, 170, 170);
margin: 1%;
width: 30%;
}
.square {
height: 23%;
width: 23%;
background-color: rgb(121, 120, 117);
margin-left: 1%;
margin-right: 1%;
justify-content: center;
align-items: center;
font-size: 5vh;
color: rgb(121, 120, 117);
}
h1, h2 {
text-align: center;
}
(The .square CSS selector styles the tiles)