Reputation: 29957
I use flexbox
for my layout and after completing Flexbox Froggy I tried to get the following alignment:
My thinking is the following:
<div>
) need to flow in a column: flex-direction: column;
align-content: flex-start;
align-self: flex-end;
This leads to the HTML code below (also available on JSFiddle)
<div class="container">
<div class="box1">
box 1
</div>
<div class="box2">
box 2
</div>
<div class="box3">
box 3
</div>
</div>
with the CSS
.container {
display: flex;
flex-direction: column;
align-content: flex-start;
}
.box3 {
align-self: flex-end;
}
But it does not work - it looks like to third box is pushed (flex-end
) to the right and not to the bottom.
My understanding was that align-self
handles an exception relative to the container ("the container aligns everything from the top, but I, myself, will align to the bottom"). Isn't that so?
Upvotes: 6
Views: 2083
Reputation: 90
More appropriate approach would be to give your container a height in Percentage rather than Pixels if that's what you want.
.container {
display: flex;
flex-direction: column;
align-content: flex-start;
height: 100%;
}
.box3 {
margin: auto 0;
}
Upvotes: 0
Reputation: 114991
You don't need to use align-self
, you can do this with margin-auto
.
.container {
display: flex;
flex-direction: column;
align-content: flex-start;
height: 150px;
border:1px solid grey;
}
.box3 {
margin-top: auto;
background:lightgreen;
}
<div class="container">
<div class="box1">
box 1
</div>
<div class="box2">
box 2
</div>
<div class="box3">
box 3
</div>
</div>
Upvotes: 6