悬停时,如何让文本每一行都出现线条?
问题所描述的悬停效果可以通过 css 的 :after 伪元素实现。然而,在原始代码中,当
元素内容太长时,只能显示一行下划线。
为了让每一行文本在悬停时都能出现下划线,需要对 css 代码进行修改。
元素的 display 属性中添加 inline 值,使其可以在同一行显示文本。
添加一个新的 css 类 test,并为其设置以下样式:
.test { display: inline; transition: all .5s; background: linear-gradient(270deg, #00000036, #00ff53cf) 0 0; background-size: 100% 2px; background-repeat: no-repeat; background-position: 0% 100%; } .test:hover { background: linear-gradient(270deg, #00ff53cf, #00ff53cf) 0 0; background-size: 100% 2px; background-repeat: no-repeat; background-position: 0% 100%; }
元素中添加 test 类。
修改后的代码如下:
<p class="test"> 这是一段测试文本 这是一段测试文本 这是一段测试文本 这是一段测试文本 这是一段测试文本 这是一段测试文本 这是一段测试文本 这是一段测试文本 这是一段测试文本 这是一段测试文本 这是一段测试文本 这是一段测试文本 这是一段测试文本 这是一段测试文本 这是一段测试文本 </p>
.test { display: inline; transition: all .5s; background: linear-gradient(270deg, #00000036, #00ff53cf) 0 0; background-size: 100% 2px; background-repeat: no-repeat; background-position: 0% 100%; } .test:hover { background: linear-gradient(270deg, #00ff53cf, #00ff53cf) 0 0; background-size: 100% 2px; background-repeat: no-repeat; background-position: 0% 100%; }
现在,每一行文本在悬停时都会出现下划线。
以上就是如何让悬停的文本每一行都出现下划线?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号