I'm going to post a solution that I got here that I found interesting and solved some bugs.
The main thing here was to make a small hake for the underline
legal render. For this I needed to use a transparent linear-gradient as the span background. I do not wonder why, because I discovered this accidentally ... While I was testing the behavior of the animated element I put background-color
in it and I noticed that bug stopped, however using color in rgba()
o problem comes back, but with a background-imagem: linear-gradiend
does not happen, at least in Chrome !
I also needed to use the text-underline-position: under;
property to fix this issue in Chrome :
SeetheresultInChromeandFireFox
Ialsohadtomakeadjustmentsusingdisplay:inline-block,
overflow
andheight
tocontrolhowthelinewillgetcutetc...
Followthecodeused:
div {
font-family: sans-serif;
font-size: 2rem;
}
div span,
div .efeito{
display: inline-block;
height: 60px;
overflow: hidden;
}
div .efeito{
font-weight: bold;
text-decoration: underline;
text-decoration-color: orange;
text-underline-position: under;
position: relative;
}
div .efeito:hover{
text-decoration: none;
}
div .efeito::after{
content: attr(data-text);
width: 100%;
color: transparent;
position: absolute;
top: 0;
left: 15px;
transition: 0s linear;
text-decoration: none;
text-decoration-style: none;
text-decoration-color: orange;
display: inline-block;
height: 60px;
text-underline-position: under;
background-image: linear-gradient(rgba(0,0,0,0.0), rgba(0,0,0,0.0));
z-index: -1;
}
div .efeito:hover::after {
animation: underx 500ms infinite linear;
text-decoration: underline;
text-decoration-style: wavy;
text-decoration-color: orange;
}
@keyframes underx {
to {
left: 0px;
}
}
<div>
<span class="efeito" data-text="meuy texto 123">meuy texto 123</span> <span>segue conteúdo.</span>
</div>
OBS: In different size fonts you will most likely need to adjust values that are in PX