The text will be placed in the center, and the button will be placed between the text and the bottom.
You can use a combination of auto fields with an invisible flexibility element to achieve the layout:
(Edit: I wrote this answer before the question was updated with sample code. Thus, my code is different from the question, but the method is still applied.)
html, body { height: 100%; margin: 0; } .container { display: flex; flex-direction: column; align-items: center; height: 100%; box-sizing: border-box; } .container > div:nth-child(1) { margin-top: auto; visibility: hidden; } .container > div:nth-child(2) { margin-top: auto; } .container > div:nth-child(3) { margin-top: auto; margin-bottom: auto; } .container { background-color: yellow; } .box { height: 50px; width: 150px; background-color: lightgreen; display: flex; justify-content: center; align-items: center; font-size: 1.2em; box-sizing: border-box; }
<div class="container"> <div class="box">BUTTON</div> <div class="box">SUPERMAN</div> <div class="box">BUTTON</div> </div>
jsFiddle
In addition, with two minor adjustments, the bottom element may be flush with the edge .
.container > div:nth-child(1) { visibility: hidden; } .container > div:nth-child(2) { margin-top: auto; } .container > div:nth-child(3) { margin-top: auto; }
jsFiddle
OR, just use justify-content: space-between :
.container > div:nth-child(1) { visibility: hidden; } .container { display: flex; flex-direction: column; align-items: center; background-color: yellow; height: 100%; box-sizing: border-box; justify-content: space-between; }
jsFiddle
For more alignment options, see Flex Element Alignment Methods.
source share