I am currently designing a grid composed of 1:1 squares and allowing the user to continually add more squares. My main goal is to ensure that the size of each square maintains its aspect ratio while being able to resize accordingly. The challenge lies in keeping the squares visible on the page without any need for scrolling, making the webpage responsive in terms of both width and height.
While testing, I have managed to create an example where a new square is added every second. However, I am facing difficulties in maintaining the height aspect of the squares, even though I have successfully implemented it for the width.
setInterval(() => {
// console.log(document.getElementsByClassName('square-container')[0]);
document.getElementsByClassName('square-container')[0].innerHTML += ("<div class='square'></div>");
}, 1000);
.square-container {
display: flex;
flex-wrap: wrap;
}
.square {
position: relative;
flex-basis: calc(33.333% - 10px);
margin: 5px;
box-sizing: border-box;
background: red;
transition: background 1s;
}
.square::before {
content: "";
display: block;
padding-top: 100%;
}
<div class="square-container">
<div class="square"></div>
</div>
I am utilizing only basic HTML, CSS, and JavaScript without relying on UI libraries like Bootstrap.