简体   繁体   English

如何使用尾风在悬停时向我的图像(不是背景)添加渐变过渡

[英]how to add gradient transition to my image (not background) on hover using tailwind

i want to put gradient color of #323232 (0% on the top and 90% on the bottom) on IMAGE hover but instead i only changed its bg.我想在 IMAGE 悬停上放置 #323232 的渐变颜色(顶部为 0%,底部为 90%),但我只更改了它的背景。 i tried to change the opacity & change the color but it's still a solid color not gradient.我试图改变不透明度并改变颜色,但它仍然是纯色而不是渐变。

this is my code这是我的代码

<Layout>
      <Container>
        <div className="grid grid-cols-3 px-{100}">
          {gallery.map((el, i) => {
            return (
              <img className="transition duration-500 transition-all hover:bg-primary-hover hover:opacity-10 delay-100" src={gallery[i].imgSrc} />
            )
          })}
        </div>
      </Container>
    </Layout>

this is how i wanted it to be: click here这就是我想要的样子:点击这里

You can add the image hover by placing a div below the image and applying the gradient to this div, then on hovering the image, you can change the opacity of image.您可以通过在图像下方放置一个 div 并将渐变应用到该 div 来添加图像悬停,然后在悬停图像时,您可以更改图像的不透明度。

I had put black and white color, however you use your choice of colour.我已经设置了黑白颜色,但是您使用您选择的颜色。

Below is the code,下面是代码,

    <script src="https://cdn.tailwindcss.com"></script>    <div class="relative mix-blend-overlay">      <img src="http://codeskulptor-demos.commondatastorage.googleapis.com/GalaxyInvaders/back05.jpg" alt="BannerImage" class="absolute h-[70vh] lg:h-[80vh] w-full object-cover object-right hover:opacity-50 " />      <div class="absolute -z-10 bg-gradient-to-t from-white via-gray-900 to-black h-[70vh] lg:h-[80vh] w-full" />    </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM