The traditional way to remove text-decoration from only a child element was to make it an inline-block. (Example 1 in Fiddle)
However, this method does not work in flexbox.
How can I remove the underline from just the icon in Example 2?
.div1 {
text-decoration: underline;
.icon {
display: inline-block;
text-decoration: none;
}
}
.div2 {
display: flex;
align-items: center;
text-decoration: underline;
.icon {
display: inline-block;
text-decoration: none;
}
}
Fiddle: https://jsfiddle.net/mz4y3jgL/8/
Wrap the content in a span element, like you've done for the icon.
Anonymous flex items, such as unwrapped text, cannot be targeted with CSS (related post).
.div2 {
display: flex;
align-items: baseline;
}
.div2 > :not(.icon) {
text-decoration: underline;
}
<div class="div2">
<span>Example 2</span>
<span class="icon">💖</span>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With