I am trying to achieve a responsive layout where I have two cards next to each other that need to grow and shrink in the width and height based on the dimensions of the container. The following image shows what I am trying to achieve and a codepen with two examples.
I essentially want the two examples from the codepen together. That either resizing the height or width changes the cards to the correct width and height following the 1/1 aspect and that overflow never happens.
In the codepen I have two examples, in the first container the cards grow when you increase or decrease the width. In the seconds container, the cards grow or shrink when you change the height of the container. https://codepen.io/aspyryan/pen/mdzVMpg
This is essentially what I want to fix, the cards should be resized instead of growing outside of the container:
this is my html:
<div class="container">
<div class="test">
<div class="el"></div>
<div class="el"></div>
</div>
</div>
<div class="container2">
<div class="el el2"></div>
<div class="el el2"></div>
</div>
with the css:
.container {
resize: both;
overflow: auto;
width: 300px;
heigth: 300px;
}
.test {
border: 2px solid blue;
display: flex;
flex-direction: row;
width: 100%;
}
.container2 {
resize: both;
overflow: auto;
width: 500px;
height: 200px;
border: 2px solid blue;
display: flex;
flex-direction: row;
}
.el {
display: block;
flex: 1;
aspect-ratio: 1/1
}
.el2 {
flex: 0!important;
}
.el:first-of-type {
background-color: red;
}
.el:last-of-type {
background-color: blue;
}
2
Answers
I don’t know if that really answer your request.
What about defining an outer container. This will have a "size", the size you want. In fact with 2 elements, aspect ratio 2/1.
Inside you define a grid for the 2 elements with width and height 100%.
try that and adapt it, I don’t have rest of your code, not easy to answer exactly, but you have main idea to adapt…
the idea is always to have somewhere a defined size, here container, and all other values are base in percentage on this one