css - 如何在背景上放置过渡(颜色到径向渐变)
问题描述
我有一个背景设置为颜色的元素
悬停背景设置为radial-gradient
我想在悬停时在颜色之间进行转换,但它会产生奇怪的效果,我的元素会消失一秒钟。
这是链接
是否可以在没有这个问题的情况下在颜色和渐变之间切换?
.link {
display: block;
position: absolute;
bottom: 20%;
padding: 0 25px;
height: 42px;
line-height: 42px;
border-radius: 8px;
font-size: 15px;
font-weight: 700;
background: red;
color: white;
transition: all 0.3s ease-in-out;
}
.link:hover {
text-decoration: none;
background: radial-gradient(98px 98px at center center, red 0%, #0088b5 100%);
}
解决方案
您可以使用背景大小:
.link {
display: inline-block;
padding: 0 25px;
line-height: 42px;
border-radius: 8px;
font-size: 15px;
font-weight: 700;
background-image: radial-gradient(circle,red 0%, #0088b5 100%);
background-position:center;
background-size:600% 600%; /*a big size to see only the red*/
color: white;
text-decoration: none;
transition: all 0.3s ease-in-out;
}
.link:hover {
background-size:150% 150%; /* reduce the size to see the gadient effect*/
}
<div class="link">Link</div>
推荐阅读
- javascript - 我如何动态地从对象中提取所有元素
- javascript - 如何从 FormData 中检索信息
- paw-app - 我可以将登录用户的用户名作为 Paw 动态值获取吗?
- swift - 使用自定义转换时,为什么 UIDropShadowView 插入呈现视图控制器?
- django - 保存订单后如何删除用户购物车?django
- sql - 需要在目标 oledb 表之后添加 substring() 列
- python - 比较两个 csv 文件后读取和写入同一个 csv 文件
- c# - 重试失败后使用 Polly 重试不同的 Url
- botframework - botskills 连接:“导入最新版本的 virtualassistanten_Dispatch 应用程序失败”
- python-3.x - 使用 apscheduler 进行多处理