I'm struggling to create a responsive grid of images. I can't get the images to be both responsive with max-height and max-width, while also making sure the parent div takes up their full width. On the other hand, if I make the parent div the correct width, the images lose their responsiveness. Can anyone provide guidance on how to achieve this dual functionality successfully?
#grid_area {
display: flex;
height: 100%;
width: 100%;
position: absolute;
align-content: center;
justify-content: center;
align-items: center;
}
#grid {
position: relative;
display: flex;
flex-direction: column;
align-items: flex-start;
height: 80%;
width: 50%;
}
img {
max-width: 100%;
max-height: 100%;
object-fit: contain;
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div id="grid_area">
<div id="grid">
<div class="row" id="0">
<img src="https://source.unsplash.com/random/460x345/" id="A1">
<img src="https://www.w3schools.com/css/img_chania.jpg" id="B1">
<img src="https://www.w3schools.com/css/img_chania.jpg" id="C1">
</div>
<div class="row" id="1">
<img src="https://www.w3schools.com/css/img_chania.jpg" id="A2">
<img src="https://www.w3schools.com/css/img_chania.jpg" id="B2">
<img src="https://www.w3schools.com/css/img_chania.jpg" id="C2">
</div>
<div class="row" id="2">
<img src="https://www.w3schools.com/css/img_chania.jpg" id="A3">
<img src="https://www.w3schools.com/css/img_chania.jpg" id="B3">
<img src="https://www.w3schools.com/css/img_chania.jpg" id="C3">
</div>
<div class="row" id="3">
<img src="https://www.w3schools.com/css/img_chania.jpg" id="A4">
<img src="https://www.w3schools.com/css/img_chania.jpg" id="B4">
<img src="https://www.w3schools.com/css/img_chania.jpg" id="C4">
</div>
</div>
</div>
</body>
</html>