I am developing a CSS and JavaScript-based game that requires the game field to be square and adjust its width and height based on the height of the viewport. In case the viewport width is smaller than the height, I need the field size to adapt while maintaining a 1:1 ratio.
Below is my current code:
<div class="field">
<div class="player">
</div>
</div>
.field {
width: 75vh;
height: 75vh;
background: #B2EBF2;
border: 1.25vh solid #0097A7;
}
.field .player {
width: 5vh;
height: 5vh;
background: #727272;
}
The current setup works well when adjusting the window/viewport height, but fails to respond to changes in width. How can I ensure that the div remains responsive and maintains a square shape regardless of changes in the viewport width?
Appreciate any guidance on this matter.