I have a grid of cards and when I hover over one card the bottom section of this card expands to show more content.
The problem is that when it expands it pushes all other cards down. Instead, I would like it to layer itself on top of the card that is situated underneath. Here are some images to visualize what I’m talking about.
CodePen Example: https://codepen.io/adrenaline681/pen/qBMqrEy
As you can see here there is empty white space underneath:
And here is an example of how I would like it to be. As you can see, the middle card has just expanded on top of the bottom card without pushing it down:
Here is how the CSS looks like:
.grid {
display: grid;
width: 60%;
margin: 0 auto;
grid-template-columns: 1fr 1fr 1fr;
gap: 15px;
}
.card {
transition: all 0.3s linear;
}
.card:hover {
transform: scale(1.04)
}
.card:hover .description {
max-height: 100px;
}
.image {
aspect-ratio: 1.6;
background-color: #516d9b;
display: flex;
justify-content: center;
align-items: center;
}
.title {
display: flex;
justify-content: center;
align-items: center;
height: 100px;
background-color: #3f8539;
}
.description {
transition: all 0.3s linear;
display: flex;
justify-content: center;
align-items: center;
max-height: 0;
overflow: hidden;
height: 100px;
background-color: #c99753;
padding-left: 25px;
}
2
Answers
No need for Codepens here on Stack Overflow. We have snippets!
In this snippet I have made the adjustments to your code to implement the behaviour you are looking for.
If you don’t care about keeping the transitions, the solution by Brett is simple and works. If you do want the transitions, then you’ll need a way to force the description panel to slide above its subsequent siblings. To do that you can add z-index to the card that is hovered instead of the description.