I have 3 divs that are side by side using display: flex.
The content in these divs are of varying height, but what I would like is to create a link in each that is always positioned at the bottom.
----------- ----------- -----------
| img | | img | | img |
| heading 1 | | heading 3 | | heading 3 |
| paragraph | | paragraph | | paragraph |
| paragraph | | | | paragraph |
| | | | | paragraph |
| link | | link | | link |
----------- ----------- -----------
This way the links will always appear lined up.
JSFiddle code
A multi-row layout where we need to place an element to the bottom of its parent container can be created easily using CSS flex. The trick is to set margin-top: auto for the last element so that the top margin is automatically set as the per the remaining space left.
Like last time, you must know the width and height of the element you want to center. Set the position property of the parent element to relative . Then set the child's position property to absolute , top to 50% , and left to 50% . This just centers the top left corner of the child element vertically and horizontally.
With the existing markup, using flex-direction: column , you can't make those two "buttons" align side-by-side. One way is to change to row wrap and make all the input + label 100% width, which can be done with either width: 100% (used below) or flex-basis: 100% .
You could change the display
of .content
to flex
, then add flex-direction: column
in order to make the content flow from top to bottom. In order to position the child anchor element at the bottom, simply add add margin-top: auto
to it:
Updated Example
.content {
display: flex;
flex-direction: column;
}
.content a {
margin-top: auto;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With