I am trying to get a little description card to pop out from behind an image in a div within a grid. I got the transitions working well, but I need to get the card behind the image.
This is the relevant html:
<div id="games_grid">
<div class="game_box">
<a href="mrstretch.html">
<img src="images/LibraryCapsule.png" alt="Mr. Stretch cover art">
</a>
<div class="description_card">
<h3>Mr. Stretch and the Stolen Fortune</h3>
<p>Description</p>
<p class="status">currently in development</p>
</div>
</div>
<div class="game_box">
<a href="#">
<img src="images/BoulderManiacE.png" alt="Boulder Maniac cover art">
</a>
<div class="description_card">
<h3>Boulder Maniac</h3>
<p>Description</p>
<p class="status"> planned developement</p>
</div>
</div>
</div>
this is the css:
.description_card {
width: 50%;
margin-left: auto;
margin-right: 10%;
margin-top: -150%;
position: relative;
z-index: -2;
}
.game_box {
background-color: #df5526;
width: 100%;
z-index: 2;
}
#games_grid {
display: grid;
grid-template-columns: repeat(5, 25%);
overflow: scroll;
overflow-y: hidden;
}
When I do that, it makes the div height size relative to the vertical position of the card, causing the image that it is behind to overflow off the div, becoming hidden by the grid's overflow rule. What it looks like with negative margin-top displacement. Commenting out the description card makes the grid height match the image height.
What I want is for the div Hight to be decided solely by the image height, not being influenced by the position of the description whatsoever. I cannot set the height manually, as it needs to scale along with the image. I can only use html and CSS.
I tried adding bottom padding to the div that has the same relative size as the card displacement, expecting that this would compensate for the displacement of the div's bottom. This did prevent overflow, but the padding goes farther than expected. The padding grows as the page is made narrower, the access eventually becoming larger even than the image, making the page much longer than it should be.
By using absolute positioning, the card can be positioned without influencing the size of the div:
This also makes the code shorter. :)