I have en element of text that contains a pseudo element to control the underline. What I want to achieve is when the element reaches two lines (or more), I want the underline to be 100 % width of the element, but now it only goes 100 % of the last row (see screenshot).
I've put up a fiddle to show you what I mean: https://jsfiddle.net/m6rmxuoy/1/
There are two examples: one with display: inline
for the h2
element:
.wrapper {
width: 260px;
h2 {
position: relative;
display: inline;
background-color: yellow;
&:after {
position: absolute;
left: 0;
bottom: 0;
width: 80px;
height: 3px;
background-color: #0077bc;
content: '';
}
&:hover:after {
width: 100%;
}
}
}
The problem with this is that the width of the line in hover state doesn't fill up to the width of the first line.
The second try, with display: inline-block
, adapts to the wrappers width instead of stopping at the longest line, as display: inline
does:
.wrapper2 {
width: 260px;
h2 {
position: relative;
display: inline-block;
background-color: yellow;
&:after {
position: absolute;
left: 0;
bottom: 0;
width: 80px;
height: 3px;
background-color: #0077bc;
content: '';
}
&:hover:after {
width: 100%;
}
}
}
The result I want to achieve is this:
I've googled for quite some time now, even found the box-decoration-break: clone;
, but it doesn't help me with pseudo elements.
Any ideas?