I want each row of the flex container to fit as many flex elements of random width as possible, up to a certain maximum container width, and the flex container width must shrink to the width of the widest resulting row.
When I try to create a flex container with a certain maximum width, there is always some surplus space between the widest row and the edge(s) of the container.
I have searched for hours but cannot find a solution.
Example:
.photos {
max-width: 500px;
margin: 0px auto 0px auto;
box-shadow: 0px 1px 3px rgba(0,0,0,0.16);
display: flex;
flex-wrap: wrap;
justify-content: center;
border: 1px solid black;
}
.photo {
height: 50px;
border: 1px solid red;
}
<!DOCTYPE html>
<head>
<link rel="stylesheet" href="flex_container.css">
</head>
<body>
<div class="photos">
<div class="photo" style="width: 155px"></div>
<div class="photo" style="width: 254px"></div>
<div class="photo" style="width: 233px"></div>
<div class="photo" style="width: 387px"></div>
</div>
</body>