html - 内容内的链接,背景从左到右填充,然后从右到左填充,这样看起来盒子正在向右滑动
问题描述
我正在尝试在链接上执行动画,背景应该从左到右填充,然后背景应该反转并从右到左。我为第一部分创建了一支笔:
p {
color: #000;
}
a {
background: linear-gradient(to right, #903e77 50%, transparent 50%);
background-size: 200% 100%;
background-position: right bottom;
color: #000;
text-decoration: none;
}
a:hover {
background-position: left bottom;
transition: background 250ms ease-in-out;
}
<p>This is a sentence with a <a href="#">link</a> in the middle.</p>
我认为这需要一个 span 元素或内部的东西来充当另一个背景块。
效果类似于此处的链接:
在页脚是最引人注目的。
解决方案
你可以像这样调整它:
p {
color: #000;
font-size: 40px;
}
a {
background: linear-gradient(#903e77, #903e77);
background-size: 200% 100%;
background-position: 200% 0;
background-repeat: no-repeat;
color: #000;
text-decoration: none;
}
a:hover {
background-position: -100% 0;
transition: background 0.5s ease-in-out;
}
<p>This is a sentence with a <a href="">link</a> in the middle.</p>
或者像这样:
p {
color: #000;
font-size: 40px;
}
a {
background: linear-gradient(#903e77, #903e77);
background-size: 0 100%;
background-position: left;
background-repeat: no-repeat;
color: #000;
text-decoration: none;
transition: background-size 0.5s,background-position 0s 0.5s;
}
a:hover {
background-size:100% 100%;
background-position:right;
}
<p>This is a sentence with a <a href="">link</a> in the middle.</p>
也像这样:
p {
color: #000;
font-size: 40px;
}
a {
background: linear-gradient(#903e77, #903e77);
background-size: 200% 100%;
background-position: 200% 0;
background-repeat: no-repeat;
color: #000;
text-decoration: none;
transition:background-position 0.5s;
}
a:hover {
background-position: -100% 0;
}
<p>This is a sentence with a <a href="">link</a> in the middle.</p>
推荐阅读
- python - 如何在 Numpy 中获取大于阈值的最大 N 值的索引?
- python - 用于提取字典特定部分的 for 循环方法
- audio - Gstreamer 合并实时音频(麦克风输入)和视频(网络摄像头输入)管道以通过 UDP 发送
- django-models - 方法 __str__ 输出所有作为回报的字段
- ios - 在 MacBook Air M1 上构建 iOS Flutter App 时出错
- c# - ids4如何根据用户id从数据库中获取用户生成access_token
- spring-boot - 如何使用从一对一或一对多关系获得的行执行 JPQL?
- python - suds-py3 中的日期时间格式
- visual-c++ - C26434 函数 xxx 隐藏了一个非虚拟函数
- iframe - 为什么我不能跨站点和跨框架获取对象 URL(又名“blob URL”)?