Reputation: 2205
I have the following layout http://jsbin.com/joyetaqase/1/edit?html,css,output
<div class="row">
<div class="col">
<h2>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</h2>
<p>my footer</p>
</div>
<div class="col">
<h2>Lorem Ipsum.</h2>
<p>my footer</p>
</div>
</div>
Using flexbox I'm trying to make same height and same width to the .col
divs.
My question is: how can I put the <p>
to stick at the bottom of the box?
Layout should look like:
I know I can make the <p>
absolute and use bottom:0;
but I want to achieve this with flexbox, is it possible?
Can someone explain?
Upvotes: 6
Views: 1903
Reputation: 371799
Make .col
a nested, column-direction flex container.
.col {
width: 50%;
border: 1px solid #000;
padding: 10px;
box-sizing: border-box;
/* NEW */
display: flex;
flex-direction: column; /* stack <h2> and <p> vertically */
justify-content: space-between; /* align <h2> at top and <p> at bottom */
}
Upvotes: 1
Reputation: 19341
You can do following way. Give display: flex;
flex-direction: column;
to
.col
and flex: 1 0 auto;
to h2
.row {
width: 500px;
font-family: monospace;
display:flex;
}
.col {
width: 50%;
border: 1px solid #000;
padding: 10px;
box-sizing: border-box;
display: flex;
flex-direction: column;
}
h2, p {
font-weight: normal;
margin: 0;
}
h2 {
flex: 1 0 auto;
}
<div class="row">
<div class="col">
<h2>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</h2>
<p>my footer</p>
</div>
<div class="col">
<h2>Lorem Ipsum.</h2>
<p>my footer</p>
</div>
</div>
Upvotes: 3
Reputation: 3675
Give the parents (.col
) relative positioning and then give the footers absolute positioning with the attribute bottom:0px;
.
.col {
width: 50%;
border: 1px solid #000;
padding: 10px;
box-sizing: border-box;
position:relative;
}
p{
position:absolute;
bottom:0px;
}
Upvotes: 0