2

I'm running into some difficulty positioning an element in the bottom left corner when using a flexbox. Essentially I'm trying to make the 'world' text to appear directly below the 'hello' text (ie. the bottom left corner of the flexbox).

rel {
  position: relative;
  background: rgba(255, 0, 0, 0.5);
  padding: 5px;
  margin-top: auto;
}
abs {
  position: absolute;
  background: rgba(0, 255, 0, 0.5);
  padding: 5px;
}
column {
  display: flex;
  flex-direction: column;
}
item {
  display: flex;
  align-items: center;
  flex: auto;
  border: 1px solid blue;
}
<column>
  <item>
    hello
    <br>hello
    <br>hello
    <br>hello
    <br>
    <rel>
      <abs>
        world
        <br/>world
        <br/>world
        <br/>world
        <br/>
      </abs>
    </rel>
  </item>
</column>
Michael Benjamin
  • 346,931
  • 104
  • 581
  • 701
Robbie
  • 700
  • 2
  • 6
  • 18

2 Answers2

0

Is this what you're after? What I did was make item display as flex column as well which will make additional elements fall under it as a column. Also added align-items: flex-start; to column so they are aligned properly. You can also remove the position properties as they aren't needed.

Live Demo on jsfiddle, snippet below.

CSS Changes

column {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

item {
    display: flex;
    align-items: center;
    flex: auto;
    flex-direction: column;
    border: 1px solid blue;
}

Snippet

rel{
  background:rgba(255,0,0,0.5);
  padding:5px;
}

abs{
  background:rgba(0,255,0,0.5);
  padding:5px;
}

column {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

item {
  display: flex;
  align-items: center;
  flex: auto;
  flex-direction: column;
  border: 1px solid blue;
}
<column>
 <item>
  hello<br>
  hello<br>
  hello<br>
  hello<br>
  <rel>
   <abs>
    world<br/>
    world<br/>
    world<br/>
    world<br/>
   </abs>
  </rel>
 </item>
</column>
Loktar
  • 34,764
  • 7
  • 90
  • 104
  • While that does get the desired result, I need the absolute positioning as the 'worlds' will be over other text and shouldn't disturb the content. – Robbie Nov 20 '16 at 03:35
  • 1
    @Robbie so something like this? https://jsfiddle.net/c5cbxw9q/3/ where you just add `absolute` back? – Loktar Nov 20 '16 at 03:37
  • Yep, I didn't even think that the entire thing was now relative to the flex box, so all you needed was to change the relative to a absolute. – Robbie Nov 20 '16 at 04:03
0

Add flex-direction: column;to the item tag. Also removing the padding will perfectly match the edges. That is the direct container that holds all the elements. Also you can remove the absolute and relative positions.

rel {
  background: rgba(255, 0, 0, 0.5);
  padding: 5px;
}
abs {
  background: rgba(0, 255, 0, 0.5);
}
column {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}
item {
  display: flex;
  align-items: center;
  flex: auto;
  flex-direction: column;
  border: 1px solid blue;
}
<column>
  <item>
    hello
    <br>hello
    <br>hello
    <br>hello
    <br>
    <rel>
      <abs>
        world
        <br/>world
        <br/>world
        <br/>world
        <br/>
      </abs>
    </rel>
  </item>
</column>