I've created a div container, which includes some checkboxes. (In the code snippet are only the labels included). I set the display to inline flex and wrap. The max width of the container is 300px. The container gets an empty space on the right (the width depends on the items of the flex box) when the items get wrapped. How can you remove this space? So the container fits the wrapped content.
.module-group {
display: inline-flex;
flex-wrap: wrap;
background-color: #fff;
border: 1px solid rgba(0, 0, 0, .125);
border-radius: 0.25rem;
max-width: 300px;
gap: .5rem;
padding: .5rem;
}
.btn-test {
color: #0d6efd;
display: inline-block;
font-weight: 400;
line-height: 1.5;
text-align: center;
text-decoration: none;
vertical-align: middle;
background-color: transparent;
border: 1px solid #0d6efd;
padding: 0.375rem 0.75rem;
font-size: 1rem;
border-radius: 0.25rem;
}
<h5>Test</h5>
<div class="module-group">
<label class="btn-test" for="aaaaaa">aaaaaa</label>
<label class="btn-test" for="bbbbbbbb">bbbbbbbb</label>
<label class="btn-test" for="cccc">cccc</label>
<label class="btn-test" for="uuid">ddddddddd</label>
<label class="btn-test" for="eeeeee">eeeeee</label>
<label class="btn-test" for="fff">fff</label>
<label class="btn-test" for="ggggggggg">ggggggggg</label>
<label class="btn-test" for="hhhhhh">hhhhhh</label>
</div>