跨多行的伪元素创建连续的下划线动画

pseudo element across multiple lines to create a continuous underline animation

我在 links 下有一条动画线。它适用于单行 links 但我有一些 links 用换行符分隔 <br> 有没有办法让动画下划线沿着 link 的所有行出现? 谢谢

body {
  padding: 20px;
  font-family: Helvetica;
}

a {
  font-weight: bold;
  color: black;
  position: relative;
  text-decoration: none;
}

a::before {
  content: "";
  position: absolute;
  width: 0%;
  height: 2px;
  bottom: 0;
  background-color: #000;
  transition: all 0.2s;
}

a:hover::before {
  width: 100%;
}
<a href="">my link</a>
<br><br>
<a href="">this is<br>a much<br>longer link</a>

像下面这样使用渐变:

body {
  padding: 20px;
  font-family: Helvetica;
}

a {
  font-weight: bold;
  color: black;
  position: relative;
  text-decoration: none;
  background:linear-gradient(#000,#000) left bottom no-repeat;
  background-size:0% 2px;
  transition: all 0.5s;
}

a:hover {
  background-size:100% 2px;
}
/* this will give another kind of animation (all lines will animate at the same time)*/
.alt {
  -webkit-box-decoration-break:clone;
          box-decoration-break:clone;
}
<a href="">my link</a>
<br><br>
<a href="">this is<br>a much<br>longer link</a>
<br><br>
<a class="alt" href="">this is<br>a much<br>longer link</a>

相关: