I am looking to display 4 quadrants on the page with no vertical or horizontal scrollbar using flexbox. I achieved this. Each quadrant will contain an image. This is where the problem comes in. The aspect ratio of the images will be the same but the sizes could vary.
I would like each image to always completely fill its div regardless of the size of the display (something like what object-fit: contain does).
The images should not overflow outside of their divs and should not create a scrollbar.
Guidelines:
- The 4 quadrants combined should fill the entire browser window with no horizontal or vertical scrollbars
- Each image must fully fill its quadrant without any overflow or padding / spacing
Here is what I have so far:
body {
padding: 0; margin: 0;
height: 100vh;
}
.item {
width: 100%;
height: 100%;
}
.container {
display: flex;
flex-wrap: wrap;
}
.container > div {
flex: 50%;
box-shadow: 0 0 0 1px black;
}
img {
width: 100%;
object-fit: contain;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="styles.css">
<!-- <script src="scripts.js"></script> -->
</head>
<body>
<div class="container">
<div class="item"><img src="https://dummyimage.com/400x200/000/fff"></div>
<div class="item"><img src="https://dummyimage.com/800x400/000/fff"></div>
<div class="item"><img src="https://dummyimage.com/1200x800/000/fff"></div>
<div class="item"><img src="https://dummyimage.com/2400x1600/000/fff"></div>
</div>
</body>
</html>