css - :before 上的多行链接动画
问题描述
就像在问题中一样,我有一个代码
如何使这种效果在许多文本行上起作用,而不是像现在这样 - 效果仅出现在例如 2 个文本行中的 1 个中(例如示例)
:root {
--00a3a3: #00a3a3;
}
a {
position: relative;
text-decoration: none; /* For Example */
}
a:before {
content: "";
position: absolute;
width: 100%;
height: 2px;
bottom: 0;
left: 0;
background-color: var(--00a3a3);
visibility: hidden;
-webkit-transform: scaleX(0);
transform: scaleX(0);
-webkit-transition: all 0.3s ease-in-out 0s;
transition: all 0.3s ease-in-out 0s;
}
a:hover:before {
visibility: visible;
-webkit-transform: scaleX(1);
transform: scaleX(1);
}
<a href="#">test</a>
<br>
<br>
<a href="#">test
<br>
test2
</a>
解决方案
使用背景结合box-decoration-break
在每一行上产生重复的效果
:root {
--00a3a3: #00a3a3;
}
a {
text-decoration: none;
background:linear-gradient(var(--00a3a3),var(--00a3a3)) bottom center no-repeat;
background-size:0% 2px;
transition: all 0.3s ease-in-out 0s;
/* Remove the below to see the diffrence */
-webkit-box-decoration-break: clone;
box-decoration-break: clone;
}
a:hover{
background-size:100% 2px;
}
<a href="#">test</a>
<br>
<br>
<a href="#">test
<br>
test2
</a>
推荐阅读
- flutter - video_player 插件上找不到文件错误
- ssl - 使用签名 URL 将文件上传到 GCP 到域名存储桶会导致 SSL 证书错误
- google-cloud-talent-solution - NodejS v4 beta 库时间戳
- javascript - 如何在 MDC 菜单中侦听 keydown Enter 和鼠标单击?
- vba - 访问表单 - 遍历一系列标签并更改标题
- android - @JsonIgnoreProperties 与 moshi 的等价物是什么?
- pandas - 如何防止 pandas 将原始数据库日期格式转换为 pandas 日期格式
- python - 替代循环遍历熊猫数据框行以应用条件?
- ruby-on-rails - 如何在 Rails 模型中映射数据?
- json - 如何转换可以表示多种类的 JSON 字符串?