I have 3 vertically centered divs in one flex container with flex-direction:column
and I need to place 3rd div to the bottom of the container.
This is an explanation of what I want: https://jsfiddle.net/tom8p7be/
How can I make this?
I have 3 vertically centered divs in one flex container with flex-direction:column
and I need to place 3rd div to the bottom of the container.
This is an explanation of what I want: https://jsfiddle.net/tom8p7be/
How can I make this?
You can add margin-top: auto
on both first and last child divs. When you add margin-top: auto
to last-child div it will push that div to end of parent but it will also push other two divs to top of the parent. That is why you also need to add margin-top: auto
to first-child div, and that will position them in the center of space from top to last-child div.
.container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-height: 100vh;
}
.container div {
margin: 5px;
padding: 5px 10px;
border: 1px solid;
}
.container > div:last-child,
.container > div:first-child{
margin-top: auto;
}
<div class="container">
<div>This div should be vertically centered</div>
<div>This one too</div>
<div>And this div shoud be placed at the bottom of the flex container</div>
</div>