【发布时间】:2026-01-17 13:25:01
【问题描述】:
我正在将 psd 文件中的投资组合部分转换为 html 代码。 This is what portfolio section looks like.
我想在悬停时为图像添加渐变背景,如您在上面的链接中看到的那样。这是我的渐变色。
linear-gradient(to right, #f659f8, #de4af8, #c33cf8, #a331f8, #7d2af9);
我知道我们不能给 img 标签提供悬停效果,并且很容易在 css 中使用 background-image 属性。但是,由于我使用magnific popup plugin,所以我必须对 a 标签内的图像使用 img 标签。
我试图解决这个问题,用 div 标签更改 img 标签并赋予它背景图像,但在此之后,插件不起作用。
问题是:img标签悬停在图片上时如何添加渐变背景?
这是我的html代码。
<div class="row portfolio-project pt-30">
<a href="https://i.stack.imgur.com/4t08s.png" class="portfolio-product col-md-4 ">
<img src="https://i.stack.imgur.com/4t08s.png" class="w-100 d-block portfolio-image">
</a>
<a href="https://i.stack.imgur.com/4t08s.png" class="portfolio-product col-md-4">
<img src="https://i.stack.imgur.com/4t08s.png" class="w-100 d-block portfolio-image">
</a>
<a href="https://i.stack.imgur.com/4t08s.png" class="portfolio-product col-md-4 ">
<img src="https://i.stack.imgur.com/4t08s.png" class="w-100 d-block portfolio-image">
</a>
<a href="https://i.stack.imgur.com/4t08s.png" class="portfolio-product col-md-4 pt-30">
<img src="https://i.stack.imgur.com/4t08s.png" class="w-100 d-block portfolio-image">
</a>
<a href="https://i.stack.imgur.com/4t08s.png" class="portfolio-product col-md-4 pt-30">
<img src="https://i.stack.imgur.com/4t08s.png" class="w-100 d-block portfolio-image">
</a>
<a href="https://i.stack.imgur.com/4t08s.png" class="portfolio-product col-md-4 pt-30">
<img src="https://i.stack.imgur.com/4t08s.png" class="w-100 d-block portfolio-image">
</a>
</div>
这是华丽的弹出 jquery 代码。
$('.portfolio-project').magnificPopup({
delegate: 'a', // child items selector, by clicking on it popup will open
type: 'image',
gallery: { enabled: true },
zoom: {
enabled: true, // By default it's false, so don't forget to enable it
duration: 300, // duration of the effect, in milliseconds
easing: 'ease-in-out', // CSS transition easing function
}});
【问题讨论】:
标签: html jquery css hover gradient