I have a number of inline-block elements in a container which is centered. The container (light blue in the picture) is also inline-block, so it should contain its content and be as small as possible.
When these inline elements start to wrap, (because I'm making the page smaller), I want the container to continue to be as small as possible, so that the container and its content centers on my page. But the container makes room for the element that is not longer present. How can I solve this? .
This container is centered on the page:
body,html{
margin:0;
width:100%;
height:100%;
}
.card{
background-color: red;
border: 1px solid;
width:100px;
height:160px;
display:inline-block;
vertical-align:middle;
}
.card-container{
background-color: lightblue;
display: inline-block;
position: relative;
transform: translateX(-50%);
left:50%;
}
<div class="card-container">
<div class="card"></div>
<div class="card">+</div>
<div class="card"></div>
<div class="card">+</div>
<div class="card"></div>
</div>