Lots of creative solutions here... I think everyone would agree that flex is the way to go if you are comfortable using flex for layout.
I ran into an issue recently where there was extra white space added to a list and it's anchor elements...
no white space:
<ul>
<li><a>link</a><span>icon</span></li>
</ul>
white space:
<ul>
<li>
<a>link</a>
<span>icon</span>
</li>
</ul>
In the application, a pseudo selector adds a bullet to each list element, but the bullet spacing is inconsistent between each list that has extra white space versus no extra white space. This creates a problem when trying to style the list content and bullet especially during text wrapping.
To fix, I displayed each li as a flex object and the white space gets removed without needing to remove it from the actual HTML. Note, you can also try using display: table; but it only works in Chrome and not Firefox.
ul li {
display: flex;
}
See code demo. Hope this helps.
ul {
border: 1px solid gray;
list-style: none;
margin: .5em 0;
padding: 1em;
width: 140px;
}
ul li {
margin: 5px 0 5px 15px;
}
ul li::before {
content:"\00BB" !important;
margin-left: -12px;
}
ul li a {
color: #006699;
font-size: 1em;
font-weight: 500;
line-height: 1.4em;
text-decoration: underline;
}
ul.removewhitespace li {
display: flex;
width: min-content;
}
ul.removewhitespace li span {
display: flex;
flex: 0 1 100%;
align-self: end;
margin-left: -.1em;
}
.icon-check {
content: "";
background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='currentColor' class='bi bi-check-circle-fill' viewBox='0 0 16 16'%3E%3Cpath d='M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zm-3.97-3.03a.75.75 0 0 0-1.08.022L7.477 9.417 5.384 7.323a.75.75 0 0 0-1.06 1.06L6.97 11.03a.75.75 0 0 0 1.079-.02l3.992-4.99a.75.75 0 0 0-.01-1.05z'/%3E%3C/svg%3E") no-repeat center 0;
background-size: auto;
background-size: 15px;
display: inline-block;
width: 17px;
height: 17px;
vertical-align: middle;
}
<ul class="removewhitespace">
<li>
<a href="#">Remove whitespace in this list with flex.</a><span class="icon-check"></span></li>
</ul>
<ul>
<li>
<a href="#">Leave the whitespace in this list as is.</a><span class="icon-check"></span></li>
</ul>