Transforming and filtering images results in overlay
P粉276876663
P粉276876663 2023-09-15 20:58:43
0
1
899

I found a code that increases the size of the image when you hover it, and the hovered image doesn't get cropped by other images: TutorialRepublic.com

But when I also enter this code:

img { transition: filter .5s ease-in-out; -webkit-filter: grayscale(100%); filter: grayscale(100%); } img:hover { -webkit-filter: grayscale(0%); filter: grayscale(0%); }

When you hover the mouse, the images will become larger and will not turn gray, but the images will overlap each other. Is there a way to make it work without the images overlapping each other.

P粉276876663
P粉276876663

reply all (1)
P粉649990163

Addposition:relativeto the image and change thez-indexon hover so that the image overlaps the other images. Here is an example of using variables:

ul { list-style: none; display: flex; gap: 1rem; } img { --grayscale: 100%; --zindex: 1; --scale: 1; --radius: 0; inline-size: 125px; aspect-ratio: 1; transition: filter .5s ease-in-out; filter: grayscale(var(--grayscale)); transform: scale(var(--scale)); box-shadow: 0 0 var(--radius) rgba(0, 0, 0, 0.5); position: relative; z-index: var(--zindex); } a:hover img { --grayscale: 0; --zindex: 2; --scale: 1.5; --radius: 10px; }
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!