html - CSS悬停以清除背景上的线性渐变失败
问题描述
我想清除背景图像上的深色线性渐变,但尝试了它不起作用,它也有闪烁的问题。
.image {
background: linear-gradient(rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.8)), url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/owl1.jpg') center no-repeat;
background-size: cover;
width: 100px;
height: 100px;
border-radius: 10px;
transition: background 0.2s ease;
}
.image:hover {
background: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/owl1.jpg') center no-repeat;
background-size: cover;
}
<div class="image">
</div>
解决方案
尝试使用 :before
.image {
position:relative;
background: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/owl1.jpg') center no-repeat;
background-size: cover;
width: 100px;
height: 100px;
border-radius: 10px;
}
.image:before{
position:absolute;
top:0;
left:0;
width:100%;
height:100%;
content:'';
border-radius: 10px;
opacity:1;
background: linear-gradient(rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.8));
transition: opacity 0.2s ease;
}
.image:hover:before{
opacity:0;
}
<div class="image"></div>
推荐阅读
- reactjs - 第 9 行:期望一个赋值或函数调用,而是看到一个表达式 no-unused-expressions
- node.js - 将 youtube-dl 脚本上传到 Google Cloud 存储
- python - 更新用户模型时如何更新我的 UserProfile 模型 Django
- java - 从另一个类访问对象数组
- excel-formula - 索引单元格参考
- python - wn.synset('whale.n.01') 返回错误的同义词集
- harp.gl - 如何在 harp.gl 中绘制地下层并将相机设置为它
- spamassassin - 无法使 SpamAssassin 主题规则生效
- python - 单击其中一个时,在运行相应 python 文件的 pyqt4 中构建按钮
- javascript - 对本地存储进行排序(数组/字符串化)