Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Align an element to centre bottom of each flexbox [duplicate]

Tags:

html

css

flexbox

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

like image 756
smally Avatar asked Jan 01 '16 03:01

smally


People also ask

How do you put an element at the bottom of a div Flex?

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.

How do I center a single item in CSS?

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.

How do I align two items in Flexbox?

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% .


1 Answers

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;
}
like image 74
Josh Crozier Avatar answered Sep 20 '22 16:09

Josh Crozier