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

pseudo element across multiple lines to create a continuous underline animation(跨多行的伪元素以创建连续的下划线动画)
本文介绍了跨多行的伪元素以创建连续的下划线动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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>

相关:

How to animate underline from left to right?

How can I achieve a CSS text loading animation over multiple lines?

这篇关于跨多行的伪元素以创建连续的下划线动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

wkhtmltopdf print-media-type uses @media print ONLY and ignores the rest(Wkhtmltopdf print-media-type仅使用@media print,而忽略其余内容)
Minify CSS with Node-sass(使用Node-Sass缩小CSS)
How to rotate outer div not inner content(如何旋转外部div而不是内部内容)
how to apply css transform to child on parent hover(如何对父级悬停时的子级应用CSS变换)
Only transition a transform in css?(是否仅在css中转换转换?)
CSS transform doesn#39;t change CSS layout(Css转换不会更改css布局)