How to get the content of the bottom element of a flexbox to be 100% height its container

gman

If I make a flexbox with 2 children and column flow and set the second child to flex-grow 1 the second child expands to fill the flexbox. This works

(ps: Didn't want to clutter the example with safari support so use Chrome or Firefox)

* {
  box-sizing: border-box;
}
html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  color: white;
}
#outer {
  display: flex;
  flex-flow: column;
  height: 100%;
}
#top { 
  background-color: red;
}
#bottom {
  background-color: blue;
  flex: 1 0 auto;
}
<div id="outer">
  <div id="top">top</div>
  <div id="bottom">bottom (blue)</div>
</div>
  

But, if I then put a child #inside inside #bottom and set its height to 100% it doesn't increase its height to match even though the flexbox has stretched #bottom.

added css

#inside {
  background-color: green;
  height: 100%;
}

html

<div id="outer">
  <div id="top">top</div>
  <div id="bottom">
    <div id="inside">inside</div>  <!- added ->
  </div>
</div>

* {
  box-sizing: border-box;
}
html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  color: white;
}
#outer {
  display: flex;
  flex-flow: column;
  height: 100%;
}
#top { 
  background-color: red;
}
#bottom {
  background-color: blue;
  flex: 1 0 auto;
}
#inside {
  background-color: green;
  height: 100%;
}
<div id="outer">
  <div id="top">top</div>
  <div id="bottom">
    <div id="inside">inside (green)</div>
  </div>
</div>

So I add a height: 100% to #bottom but now bottom is as big as #outer instead of the flex stretched size.

#bottom {
  background-color: blue;
  flex: 1 0 auto;
  height: 100%;   /* added */
} 

* {
  box-sizing: border-box;
}
html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  color: white;
}
#outer {
  display: flex;
  flex-flow: column;
  height: 100%;
}
#top { 
  background-color: red;
}
#bottom {
  background-color: blue;
  flex: 1 0 auto;
  height: 100%;
}
#inside {
  background-color: green;
  height: 100%;
}
<div id="outer">
  <div id="top">top</div>
  <div id="bottom">
    <div id="inside">inside (green) (would not scroll if working)</div>
  </div>
</div>

How do I get #bottom to stretch to fit the flexbox and also get a the child #inside to be 100% height of its container #bottom?

Ason

Flex has a quirk where you need to set the height to 0.

Change the #bottom rule's height property to this height: 0;

For the inside to work I changed it to "position: absolute" and as well added a position:relative to the bottom

Update

If you don't want to use absolute position, you can set these 2 css rules like this:

(Note though, that this propagates the original issue if a new inner div is used like the first one)

#bottom {
  position: relative;
  background-color: blue;
  flex: 1 0 auto;
  height: 0;
  display: flex;
}
#inside {
  background-color: green;
  flex: 1 0 auto;
}

Sample using "position: absolute"

* {
  box-sizing: border-box;
}
html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  color: white;
}
#outer {
  display: flex;
  flex-flow: column;
  height: 100%;
}
#top { 
  background-color: red;
}
#bottom {
  position: relative;
  background-color: blue;
  flex: 1 0 auto;
  height: 0;
}
#inside {
  background-color: green;
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
}
<div id="outer">
  <div id="top">top</div>
  <div id="bottom">
    <div id="inside">inside (would not scroll if working)</div>
  </div>
</div>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Flexbox: how to get divs to fill up 100% of the container width without wrapping?

From Dev

How to get element to fill 100% height of parent

From Dev

How to get the width of an element that breaks out of its container with javascript?

From Dev

Make a CodeMirror editor and its gutter 100% height of container

From Dev

How to flush content to bottom in container, when neither container nor content height are known?

From Dev

How to set an html element's height as { 100% - 10em from bottom }

From Dev

Make container 100% height despite no content

From Dev

How to create an element on top of the layout with 100% height, maybe flexbox?

From Dev

How to make a 100% height container in Bootstrap 3

From Dev

Flexbox item height independent of its content

From Dev

How do I get this div to height 100%? (flexbox on container)

From Dev

Position element to the bottom of a height: 100% div

From Dev

100% wide child element is not filling its container

From Dev

Get height of an element's content

From Dev

How to make flexbox child's height to fit to content instead of 100% height of its container

From Dev

Flexbox container in Chrome doesn't get 100% height

From Dev

How to get the height of a div after its content is loaded?

From Dev

How can we adjust the height of a parent element depending on its content?

From Dev

Put div in bottom of container wiht dynamic height of content-wrapper

From Dev

Footer on the bottom - 100% height

From Dev

Position element to the bottom of a height: 100% div

From Dev

How to position element on the bottom of its container?

From Dev

container height is less than its content

From Dev

How to get the height of a div after its content is loaded?

From Dev

How to push flexbox child to the bottom of its container?

From Dev

How to get 3 divs to align horizontally, with height of 100%, inside a container

From Dev

Flexbox css get height 100%

From Dev

Flexbox element height 100% going outside of parent?

From Dev

How to extend height of an element to the bottom of its parent element

Related Related

  1. 1

    Flexbox: how to get divs to fill up 100% of the container width without wrapping?

  2. 2

    How to get element to fill 100% height of parent

  3. 3

    How to get the width of an element that breaks out of its container with javascript?

  4. 4

    Make a CodeMirror editor and its gutter 100% height of container

  5. 5

    How to flush content to bottom in container, when neither container nor content height are known?

  6. 6

    How to set an html element's height as { 100% - 10em from bottom }

  7. 7

    Make container 100% height despite no content

  8. 8

    How to create an element on top of the layout with 100% height, maybe flexbox?

  9. 9

    How to make a 100% height container in Bootstrap 3

  10. 10

    Flexbox item height independent of its content

  11. 11

    How do I get this div to height 100%? (flexbox on container)

  12. 12

    Position element to the bottom of a height: 100% div

  13. 13

    100% wide child element is not filling its container

  14. 14

    Get height of an element's content

  15. 15

    How to make flexbox child's height to fit to content instead of 100% height of its container

  16. 16

    Flexbox container in Chrome doesn't get 100% height

  17. 17

    How to get the height of a div after its content is loaded?

  18. 18

    How can we adjust the height of a parent element depending on its content?

  19. 19

    Put div in bottom of container wiht dynamic height of content-wrapper

  20. 20

    Footer on the bottom - 100% height

  21. 21

    Position element to the bottom of a height: 100% div

  22. 22

    How to position element on the bottom of its container?

  23. 23

    container height is less than its content

  24. 24

    How to get the height of a div after its content is loaded?

  25. 25

    How to push flexbox child to the bottom of its container?

  26. 26

    How to get 3 divs to align horizontally, with height of 100%, inside a container

  27. 27

    Flexbox css get height 100%

  28. 28

    Flexbox element height 100% going outside of parent?

  29. 29

    How to extend height of an element to the bottom of its parent element

HotTag

Archive