我想在悬停时添加线性渐变过渡。
我做了一些研究,发现了它是如何工作的,但不幸的是,它们只适用于按钮等,而我希望它出现在图像上。
我使用css属性添加了一个图像
背景图像
。我希望当用户悬停在图像上时,图像显示线性渐变和过渡。
这是代码。
.project-1 {
background-image: url("https://cdn.pixabay.com/photo/2018/03/11/20/42/mammals-3218028_960_720.jpg");
width: 350px;
height: 250px;
background-position: center;
background-size: cover;
transition: transform 0.5s , opacity 0.5s;
}
.project-1:hover {
background-image: linear-gradient(rgba(0, 0, 0, 0.39) , rgba(0, 0, 0, 0.39)) , url("https://cdn.pixabay.com/photo/2018/03/11/20/42/mammals-3218028_960_720.jpg");
background-position: center;
background-size: cover;
transform: scale(1.05);
}
<div class="project-1"></div>
我在stackoverflow上找到的主题有按钮或简单的背景,没有任何图像。
(我在代码中使用的图像仅用于片段)