I made a JSFiddle to reenact this problem.
I am trying to get a grid element to grow when hovered, but it causes this weird problem where it goes under the other grid element, then jumps to how I expected and want it to be.
Why does this happen and is there a way to get around it?
.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>
2
Answers
You can use flexbox with the
flex
short-hand property:Try it:
I have wrote a detailed article about such effect that I invite you to read to understand how to achieve such effect using CSS grid: https://css-tricks.com/zooming-images-in-a-grid-layout/