Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to stack divs on top of each other using flexbox syntax?

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?

like image 615
Alfonso Estévez-Vilanova Avatar asked Nov 04 '14 17:11

Alfonso Estévez-Vilanova


People also ask

How do you stack items on top of each other 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.

How do I make two divs stack on top of each other?

Position the outer div however you want, then position the inner divs using absolute. They'll all stack up.

How do I put one div on top of the other?

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.


Video Answer


1 Answers

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>
like image 183
vals Avatar answered Oct 21 '22 18:10

vals