0

Clarify: This does not duplicate the question on Chrome / Safari not filling 100% height of flex parent

My question is related to container not stretching with content. Otherwise the container stretches just fine without content. The problem is when I actually start to pour content into the container to increase its height.

The "main" element should be stretching with content but it's currently not doing so. My code is below:

html, body {
    height: 100%;
    min-height: 100%;
    margin: 0;
    padding: 0;
}
header, footer {
    height: 40px;
    background: #fafafa;
    display: block;
}
#page-wrapper {
    display: flex;
    flex-direction: column;
    background: lightpink;
    min-height: 100%;
}
main {
    display: flex;
    background: darkred;
    flex: 1;
    flex-direction: row;
}
#reader {
    flex: 1;
    background: orange;
}
#splitcontent {
    background: lightblue;
    width: 200px;
}
<div id="page-wrapper">
    <header>header</header>
    <main id="content">
        <article id="reader">
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
            <p>test</p>
        </article>
        <article id="splitcontent">
        </article>
    </main>
    <footer>footer</footer>
</div>
Community
  • 1
  • 1
webkitfanz
  • 1,305
  • 1
  • 16
  • 29

2 Answers2

0

Add:

#page-wrapper {
    height:auto;
    min-height: 100%;
}

html,
body {
  height: 100%;
  min-height: 100%;
  margin: 0;
  padding: 0;
}
header,
footer {
  height: 40px;
  background: #fafafa;
  display: block;
}
#page-wrapper {
  display: flex;
  flex-direction: column;
  background: lightpink;
  height: auto;
  min-height: 100%;
}
main {
  display: flex;
  background: darkred;
  flex: 1;
  flex-direction: row;
}
#reader {
  flex: 1;
  background: orange;
}
#splitcontent {
  background: lightblue;
  width: 200px;
}
<html>

<head>
</head>

<body>
  <div id="page-wrapper">
    <header>header</header>
    <main id="content">
      <article id="reader">
        <p>test
        </p>
        <p>test
        </p>
        <p>test
        </p>
        <p>test
        </p>
        <p>test
        </p>
        <p>test
        </p>
        <p>test
        </p>
        <p>test
        </p>
        <p>test
        </p>
        <p>test
        </p>
        <p>test
        </p>
        <p>test
        </p>
        <p>test
        </p>
        <p>test
        </p>
        <p>test
        </p>
      </article>
      <article id="splitcontent">
      </article>
    </main>
    <footer>footer</footer>
  </div>
</body>

</html>
TylerH
  • 20,799
  • 66
  • 75
  • 101
Andrei Fedorov
  • 3,689
  • 2
  • 13
  • 25
0

ANOTHER CHANGE / EDIT:

Change height 100% to min-height: 100% in page-wrapper (height 100% prevents the height from growing), and remove flex: 1 from main

html, body {
    height: 100%;
    min-height: 100%;
    margin: 0;
    padding: 0;
}
header, footer {
    height: 40px;
    background: #fafafa;
    display: block;
}
#page-wrapper {
    display: flex;
    flex-direction: column;
    background: lightpink;
    min-height: 100%;
}
main {
    display: flex;
    background: darkred;
    flex-direction: row;
}
#reader {
    flex: 1;
    background: orange;
}
#splitcontent {
    background: lightblue;
    width: 200px;
}
<div id="page-wrapper">
    <header>header</header>
    <main id="content">
      <article id="reader">
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
      </article>
      <article id="splitcontent">
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
      </article>
    </main>
    <footer>footer</footer>
</div>

Works in Chrome.

Johannes
  • 64,305
  • 18
  • 73
  • 130
  • No thats not the issue. I closed the

    tags just now.

    – webkitfanz Jan 12 '17 at 14:28
  • It works on codepen for some reason but when I test this on the actual page it does not run as it should: http://myorange.ca/webkitfanz/test.html – webkitfanz Jan 12 '17 at 14:40
  • No, that won't be a solution. If I do that then I lose the #splitcontent – webkitfanz Jan 12 '17 at 15:06
  • I added another change - see edited question – Johannes Jan 12 '17 at 15:47
  • When you remove the content the #page-wrapper does not stretch to 100% content, which it should be doing. – webkitfanz Jan 12 '17 at 16:23
  • because you need to add `height: 100%` to the parent elements all the way up to `body` and `html`.So `html, body { height: 100%; }` – Johannes Jan 12 '17 at 16:29
  • How else can I get 100% of full page height of #page-wrapper? Its impossible if I don't add 100% height to body and html... – webkitfanz Jan 12 '17 at 16:52
  • `100vh` is a possibility, but old browsers won't like it... – Johannes Jan 12 '17 at 18:16
  • @Johannes I don't understand the problem using viewport units, like `vh`, since it has better browser support than `flexbox` – Asons Jan 12 '17 at 19:07
  • @LGSon You are right - I hadn't thought about that. When I write about something like `vh`, I usually add a remark about browser support, but in this case it's superfluous since flexbox is used anyway... – Johannes Jan 12 '17 at 20:20