Flexbox issue. Hopefully someone can help :)
I'm trying to build a deck of cards made of divs and stack them over each other like you would using position:absolute.
Is there any way to get divs to overlay each other in the same space using flexbox?
To display the items vertically, use flex-direction: column and the items will stack on top of one another in a column instead of side-by-side in a row. I would imagine this is due to the fact that you have . top-h1 with the position set to absolute . This should do what you want.
Position the outer div however you want, then position the inner divs using absolute. They'll all stack up.
By using a div with style z-index:1; and position: absolute; you can overlay your div on any other div . z-index determines the order in which divs 'stack'. A div with a higher z-index will appear in front of a div with a lower z-index . Note that this property only works with positioned elements.
One way to get it is to set a negative margin. A deck of cards using it:
.deck {
display: flex;
height: 200px;
flex-direction: column;
}
.card {
height: 100px;
width: 60px;
flex: 100px 1 0;
border: solid 1px black;
border-radius: 5px;
margin-bottom: -80px;
background-color: white;
box-shadow: 3px 3px 3px gray;
}
<div class="deck">
<div class="card">1</div>
<div class="card">2</div>
<div class="card">3</div>
<div class="card">4</div>
<div class="card">5</div>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With