I made a JSFiddle to reproduce this issue.
I'm trying to make a grid element grow on hover, but it causes this weird issue where it goes underneath another grid element and then jumps the way I expect it to.
Why does this happen? Is there a way to solve?
.container { height: 100vh; width: 100vw; display: grid; grid-template: 1fr / 1fr 1fr; margin: 1em; grid-gap: 1em; } .box { height: 100%; width: 100%; transition: width 0.5s; } .one { background: pink; } .two { background: red; } .box:hover { width: 60vw; }
<div class="container"> <div class="box one"></div> <div class="box two"></div> </div>
I wrote a detailed article about this effect and I invite you to read it to learn how to achieve this effect using CSS Grid: https://css-tricks.com/zooming-images-in -a-grid-layout/
You can combine Flexbox with
flex
结合使用> Shorthand properties :try it: