How can I ensure that the color swatch fills the designated space in the CSS (width: 40px) while allowing the label to shrink? The issue arises when the label is a long word such as "Corn flower blue", causing the color swatch to shrink instead of maintaining its width.
I have attempted to use Bootstrap 4 classes, specifically flex-fill and flex-grow-1 on the color swatch and flex-shrink-1 on the swatch label, but none of these combinations seem to work.
https://getbootstrap.com/docs/4.3/utilities/flex/#grow-and-shrink
For a working example, refer to the following Codepen link:
https://codepen.io/ben_jammin/pen/Vwadqqb
.container {
background-color:red;
}
.sidebar {
width:280px;
padding:1.5rem;
background-color:#efefef;
}
li {list-style-type: none;}
.color-swatch {width:40px; height:40px;}
<div class="container">
<div class="sidebar">
<ul class="swatches d-flex flex-wrap m-0 pl-0" role="menu">
<li class="swatch mb-2 col-6 px-0">
<a class="d-flex align-items-center" href="#">
<!-- Swatch -->
<span class="color-swatch d-flex flex-grow-1" style="background-color:black;"></span>
<!-- Swatch Label -->
<span class="stacked label ml-2 d-flex">Black</span></a>
</li>
<li class="swatch mb-2 col-6 px-0">
<a class="d-flex align-items-center" href="#">
<!-- Swatch -->
<span class="color-swatch d-flex flex-grow-1" style="background-color:blue;"></span>
<!-- Swatch Label -->
<span class="stacked label d-flex ml-2">Blue</span></a>
</li>
<li class="swatch mb-2 col-6 px-0">
<a class="d-flex align-items-center" href="#">
<!-- Swatch -->
<span class="color-swatch d-flex flex-grow-1" style="background-color:cornflowerblue;"></span>
<!-- Swatch Label -->
<span class="stacked label d-flex ml-2">Corn flower blue</span></a>
</li>
<li class="swatch mb-2 col-6 px-0">
<a class="d-flex align-items-center" href="#">
<!-- Swatch -->
<span class="color-swatch d-flex flex-grow-1" style="background-color:forestgreen;"></span>
<!-- Swatch Label -->
<span class="stacked label d-flex ml-2">Forest green</span></a>
</li>
<li class="swatch mb-2 col-6 px-0">
<a class="d-flex align-items-center" href="#">
<!-- Swatch -->
<span class="color-swatch d-flex flex-grow-1" style="background-color:gray;"></span>
<!-- Swatch Label -->
<span class="stacked label d-flex ml-2">Gray</span></a>
</li>
<li class="swatch mb-2 col-6 px-0">
<a class="d-flex align-items-center" href="#">
<!-- Swatch -->
<span class="color-swatch d-flex flex-grow-1" style="background-color:darkblue;"></span>
<!-- Swatch Label -->
<span class="stacked label d-flex ml-2">Midnight Blue</span></a>
</li>
</ul>
</div>
</div>