2

Consider this fiddle: https://jsfiddle.net/vs9a4toz/

I want my buttons to be at the bottom of their divs.

I tried using align-self: flex-end on their container div. But that ends up with the content of that div gets aligned at the end not the div itself.

.container {
  width: 600px;
  display: flex;
  flex-flow: row;
  border: 2px solid red;
}

.box1,
.box2,
.box3 {
  width: 100%;
  border: 1px solid blue;
  display: flex;
  flex-flow: column;
  size: 100px;
}

.content {
  text-align: center;
}

.buttons {
  display: flex;
  flex-flow: column;
}
<div class="container">

  <div class="box1">
    <div class="content">
      <p>HEJ</p>
    </div>
    <div class="buttons">
      <button>ONEONE</button>
      <button>TWOTWO</button>
    </div>
  </div>

  <div class="box2">
    <div class="content">
      <p>HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ </p>
    </div>
    <div class="buttons">
      <button>ONEONE</button>
      <button>TWOTWO</button>
    </div>
  </div>

  <div class="box3">
    <div class="content">
      <p>HEJ</p>
    </div>
    <div class="buttons">
      <button>ONEONE</button>
      <button>TWOTWO</button>
    </div>
  </div>

</div>
Asons
  • 84,923
  • 12
  • 110
  • 165
mrfr
  • 1,724
  • 2
  • 23
  • 44
  • All you need is to add `flex-grow: 1` to `content` ... https://jsfiddle.net/vs9a4toz/2/ ... which you have to if you want to give the `content` a background color ... https://jsfiddle.net/vs9a4toz/3/ ... as with `margin-top: auto` that will not look good ... https://jsfiddle.net/vs9a4toz/4/ – Asons Aug 21 '17 at 13:44

6 Answers6

6

https://jsfiddle.net/eLuyursq/

.buttons {
  display:flex;
  flex-flow: column;
  margin-top: auto;
}

Just add margin-top: auto;

radbrawler
  • 2,391
  • 2
  • 15
  • 22
  • +1 for the cleanest solution and [Flexbox and "margin-(opposite direction):auto" - relevant article](https://hackernoon.com/flexbox-s-best-kept-secret-bd3d892826b6) – FelipeAls Aug 21 '17 at 13:34
  • @FelipeAls Give the `content` a background color and suddenly this is not that good anymore...check my comment at the question – Asons Aug 21 '17 at 13:49
3

flex-grow: 1 on .content is enough to make this work:

.content {
  text-align:center;
  flex-grow: 1;
}

It will take all available free space within the .box column. (Thanks @LGSon)

Kostas Siabanis
  • 2,989
  • 2
  • 20
  • 22
0

Use margin property with flexbox

.container {
  width: 600px;
  display: flex;
  flex-flow: row;
  border: 2px solid red;
}

.box1,
.box2,
.box3 {
  width: 100%;
  border: 1px solid blue;
  display: flex;
  flex-flow: column;
  size: 100px;
}

.content {
  text-align: center;
}

.buttons {
  display: flex;
  flex-flow: column;
  margin-top: auto;
}
<div class="container">

  <div class="box1">
    <div class="content">
      <p>HEJ</p>
    </div>
    <div class="buttons">
      <button>ONEONE</button>
      <button>TWOTWO</button>
    </div>
  </div>

  <div class="box2">
    <div class="content">
      <p>HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ </p>
    </div>
    <div class="buttons">
      <button>ONEONE</button>
      <button>TWOTWO</button>
    </div>
  </div>

  <div class="box3">
    <div class="content">
      <p>HEJ</p>
    </div>
    <div class="buttons">
      <button>ONEONE</button>
      <button>TWOTWO</button>
    </div>
  </div>

</div>
sol
  • 22,311
  • 6
  • 42
  • 59
0

Try using absolute positioning, please see code below:

.buttons{
    position: absolute;
    bottom: 0px;
}

.box1,
.box2,
.box3 {
    width: 100%;
    border: 1px solid blue;
    display: flex;
    flex-flow: column;
    size: 100px;
    position: relative;
}
Lewis Browne
  • 904
  • 7
  • 23
0

bsd

check it out

https://jsfiddle.net/u1bx4473/1/

you need to position:relative the divs and then position:absolute; bottom:0; width:100% the buttons...

but if you need the content to not get hidden by the buttons, you need a container for the content with overflow:auto and fixed width or something...

kind of like this : https://jsfiddle.net/u1bx4473/2/

0

A solution using padding on content and absolute position on the buttons:

.container {
  width: 600px;
  display:flex;
  flex-flow: row;
  border: 2px solid red;
}

.box1, .box2, .box3 {
  width: 100%;
  border: 1px solid blue;
  size: 100px;
  position:relative;
}

.content {
  text-align:center;
  height: 100%;
  padding-bottom: 50px;
}

.buttons {
  position:absolute;
  bottom:0;
  width:100%;
  height:50px;
  display: flex;
  flex-flow: column;
}
<div class="container">

  <div class="box1">
    <div class="content">
      <p>HEJ</p>
    </div>
    <div class="buttons">
        <button>ONEONE</button>
        <button>TWOTWO</button>
    </div>
  </div> 
  
    <div class="box2">
    <div class="content">
      <p>HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ HEJ </p>
    </div>
    <div class="buttons">
        <button>ONEONE</button>
        <button>TWOTWO</button>
    </div>
  </div> 
  
    <div class="box3">
    <div class="content">
      <p>HEJ</p>
    </div>
    <div class="buttons">
        <button>ONEONE</button>
        <button>TWOTWO</button>
    </div>
  </div> 

</div>
eye-wonder
  • 1,181
  • 9
  • 17