Sorry for the confusing title. Couldn't come up with a better. Anyway, I would like to list items in a grid. Think products in a webshop. Each item will be a fixed width and fixed height, but the number of items can change. The end goal is to make everything responsive so it will look good both on mobile and desktop.
This is my code:
<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<style>
.container {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 1rem;
background-color: #ffaa00;
margin-left: auto;
margin-right: auto;
width: 90%;
}
.item {
width: 15rem;
height: 15rem;
background-color: #0088ff;
}
</style>
</head>
<body>
<div class="container">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
</div>
</body>
</html>
Everything is looking as expected, but I want the items that wraps (if the numbers of wrapped items are not equal to a "full" row) to be aligned to the left - not the center. But I still want all the items in a "full" row to be aligned to the center. I'll include some pictures to clarify it.
If I set "justify-content: left" all items will be aligned to the left, that's not what I want either...