I use border-bottom
to style multi-line links:
div {
display: inline-block;
width: 100px;
padding: 20px;
background-color: #ddd;
}
a {
text-decoration: none;
border-bottom: 2px solid rgba(255, 0, 255, 0.5);
}
<div>
<a href="#">StackOverflow is awesome</a>
</div>
For this to work, the <a>
needs to be an inline element.
If the <a>
appears to be a block-level element, the border is drawn only at the bottom:
And, this is exactly what is happening when the <a>
is a child of a flexbox:
div {
display: inline-flex;
width: 100px;
padding: 20px;
background-color: #ddd;
}
a {
text-decoration: none;
border-bottom: 2px solid rgba(255, 0, 255, 0.5);
}
<div>
<a href="#">StackOverflow is awesome</a>
</div>
Looks like, the children of a flex parent are automatically treated as block-level elements.
Is there a way to keep flex children as inline elements?