Flexbox with center valign and allow expandable content












3















First of all, the first snippet below is the problem I'm trying to fix.



Note that this was working perfectly fine IF display: flex; is applied to body.



However, I do not want to apply style to body which will break Google Web Cache layout.



* More explanation after the first snippet






* { box-sizing: border-box; }
body { margin: 0; }
.wrapper {
display: flex;
flex-direction: column;
min-height: 100vh;
width: 100%;
background-color: #ccc;
}
.navigation {
background-color: #f00;
width: 100%;
height: 3rem;
}
.footer {
background-color: #0f0;
width: 100%;
text-align: center;
line-height: 2rem;
}

.content {
background-color: #ff0;
flex: 1;
margin: 0.6rem 0 1.2rem;
}
.container {
background-color: #f0f;
margin: 0 auto;
max-width: 120rem;
width: 100%;
padding: 0 2rem;
}
.centered {
display: flex;
height: 100%;
align-items: center;
justify-content: center;
}
.long-content {
background-color: #fff;
}

<main class="wrapper">
<nav class="navigation">.navigation</nav>
<div class="content">
<section class="container centered">
<div class="long-content">.long-content</div>
</section>
</div>
<footer class="footer">.footer</footer>
</main>





So, removing display: flex; raised this issue:





  • section within .content does not have the height spanning across .content


Trying to fix it with position: relative on .content and position: absolute on .centered fixed the height issue but raised:




  • Width of .centered does not span across .content which can be easily fixed with left:0;right:0;

  • Height does not flow with content in section (I'm out of idea here)


Was it wrong to use position: relative and position: absolute to patch the original issue?
If so, what is the more suitable solution?






* { box-sizing: border-box; }
body { margin: 0; }
.wrapper {
display: flex;
flex-direction: column;
min-height: 100vh;
width: 100%;
background-color: #ccc;
}
.navigation {
background-color: #f00;
width: 100%;
height: 3rem;
}
.footer {
background-color: #0f0;
width: 100%;
text-align: center;
line-height: 2rem;
}

.content {
background-color: #ff0;
flex: 1;
margin: 0.6rem 0 1.2rem;
position: relative;
}
.container {
background-color: #f0f;
margin: 0 auto;
max-width: 120rem;
width: 100%;
padding: 0 2rem;
}
.centered {
display: flex;
position: absolute;
height: 100%;
left: 0;
right: 0;
align-items: center;
justify-content: center;
}
.long-content {
background-color: #fff;
height: 1000px;
}

<main class="wrapper">
<nav class="navigation">.navigation</nav>
<div class="content">
<section class="container centered">
<div class="long-content">.long-content</div>
</section>
</div>
<footer class="footer">.footer</footer>
</main>












share|improve this question





























    3















    First of all, the first snippet below is the problem I'm trying to fix.



    Note that this was working perfectly fine IF display: flex; is applied to body.



    However, I do not want to apply style to body which will break Google Web Cache layout.



    * More explanation after the first snippet






    * { box-sizing: border-box; }
    body { margin: 0; }
    .wrapper {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    width: 100%;
    background-color: #ccc;
    }
    .navigation {
    background-color: #f00;
    width: 100%;
    height: 3rem;
    }
    .footer {
    background-color: #0f0;
    width: 100%;
    text-align: center;
    line-height: 2rem;
    }

    .content {
    background-color: #ff0;
    flex: 1;
    margin: 0.6rem 0 1.2rem;
    }
    .container {
    background-color: #f0f;
    margin: 0 auto;
    max-width: 120rem;
    width: 100%;
    padding: 0 2rem;
    }
    .centered {
    display: flex;
    height: 100%;
    align-items: center;
    justify-content: center;
    }
    .long-content {
    background-color: #fff;
    }

    <main class="wrapper">
    <nav class="navigation">.navigation</nav>
    <div class="content">
    <section class="container centered">
    <div class="long-content">.long-content</div>
    </section>
    </div>
    <footer class="footer">.footer</footer>
    </main>





    So, removing display: flex; raised this issue:





    • section within .content does not have the height spanning across .content


    Trying to fix it with position: relative on .content and position: absolute on .centered fixed the height issue but raised:




    • Width of .centered does not span across .content which can be easily fixed with left:0;right:0;

    • Height does not flow with content in section (I'm out of idea here)


    Was it wrong to use position: relative and position: absolute to patch the original issue?
    If so, what is the more suitable solution?






    * { box-sizing: border-box; }
    body { margin: 0; }
    .wrapper {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    width: 100%;
    background-color: #ccc;
    }
    .navigation {
    background-color: #f00;
    width: 100%;
    height: 3rem;
    }
    .footer {
    background-color: #0f0;
    width: 100%;
    text-align: center;
    line-height: 2rem;
    }

    .content {
    background-color: #ff0;
    flex: 1;
    margin: 0.6rem 0 1.2rem;
    position: relative;
    }
    .container {
    background-color: #f0f;
    margin: 0 auto;
    max-width: 120rem;
    width: 100%;
    padding: 0 2rem;
    }
    .centered {
    display: flex;
    position: absolute;
    height: 100%;
    left: 0;
    right: 0;
    align-items: center;
    justify-content: center;
    }
    .long-content {
    background-color: #fff;
    height: 1000px;
    }

    <main class="wrapper">
    <nav class="navigation">.navigation</nav>
    <div class="content">
    <section class="container centered">
    <div class="long-content">.long-content</div>
    </section>
    </div>
    <footer class="footer">.footer</footer>
    </main>












    share|improve this question



























      3












      3








      3








      First of all, the first snippet below is the problem I'm trying to fix.



      Note that this was working perfectly fine IF display: flex; is applied to body.



      However, I do not want to apply style to body which will break Google Web Cache layout.



      * More explanation after the first snippet






      * { box-sizing: border-box; }
      body { margin: 0; }
      .wrapper {
      display: flex;
      flex-direction: column;
      min-height: 100vh;
      width: 100%;
      background-color: #ccc;
      }
      .navigation {
      background-color: #f00;
      width: 100%;
      height: 3rem;
      }
      .footer {
      background-color: #0f0;
      width: 100%;
      text-align: center;
      line-height: 2rem;
      }

      .content {
      background-color: #ff0;
      flex: 1;
      margin: 0.6rem 0 1.2rem;
      }
      .container {
      background-color: #f0f;
      margin: 0 auto;
      max-width: 120rem;
      width: 100%;
      padding: 0 2rem;
      }
      .centered {
      display: flex;
      height: 100%;
      align-items: center;
      justify-content: center;
      }
      .long-content {
      background-color: #fff;
      }

      <main class="wrapper">
      <nav class="navigation">.navigation</nav>
      <div class="content">
      <section class="container centered">
      <div class="long-content">.long-content</div>
      </section>
      </div>
      <footer class="footer">.footer</footer>
      </main>





      So, removing display: flex; raised this issue:





      • section within .content does not have the height spanning across .content


      Trying to fix it with position: relative on .content and position: absolute on .centered fixed the height issue but raised:




      • Width of .centered does not span across .content which can be easily fixed with left:0;right:0;

      • Height does not flow with content in section (I'm out of idea here)


      Was it wrong to use position: relative and position: absolute to patch the original issue?
      If so, what is the more suitable solution?






      * { box-sizing: border-box; }
      body { margin: 0; }
      .wrapper {
      display: flex;
      flex-direction: column;
      min-height: 100vh;
      width: 100%;
      background-color: #ccc;
      }
      .navigation {
      background-color: #f00;
      width: 100%;
      height: 3rem;
      }
      .footer {
      background-color: #0f0;
      width: 100%;
      text-align: center;
      line-height: 2rem;
      }

      .content {
      background-color: #ff0;
      flex: 1;
      margin: 0.6rem 0 1.2rem;
      position: relative;
      }
      .container {
      background-color: #f0f;
      margin: 0 auto;
      max-width: 120rem;
      width: 100%;
      padding: 0 2rem;
      }
      .centered {
      display: flex;
      position: absolute;
      height: 100%;
      left: 0;
      right: 0;
      align-items: center;
      justify-content: center;
      }
      .long-content {
      background-color: #fff;
      height: 1000px;
      }

      <main class="wrapper">
      <nav class="navigation">.navigation</nav>
      <div class="content">
      <section class="container centered">
      <div class="long-content">.long-content</div>
      </section>
      </div>
      <footer class="footer">.footer</footer>
      </main>












      share|improve this question
















      First of all, the first snippet below is the problem I'm trying to fix.



      Note that this was working perfectly fine IF display: flex; is applied to body.



      However, I do not want to apply style to body which will break Google Web Cache layout.



      * More explanation after the first snippet






      * { box-sizing: border-box; }
      body { margin: 0; }
      .wrapper {
      display: flex;
      flex-direction: column;
      min-height: 100vh;
      width: 100%;
      background-color: #ccc;
      }
      .navigation {
      background-color: #f00;
      width: 100%;
      height: 3rem;
      }
      .footer {
      background-color: #0f0;
      width: 100%;
      text-align: center;
      line-height: 2rem;
      }

      .content {
      background-color: #ff0;
      flex: 1;
      margin: 0.6rem 0 1.2rem;
      }
      .container {
      background-color: #f0f;
      margin: 0 auto;
      max-width: 120rem;
      width: 100%;
      padding: 0 2rem;
      }
      .centered {
      display: flex;
      height: 100%;
      align-items: center;
      justify-content: center;
      }
      .long-content {
      background-color: #fff;
      }

      <main class="wrapper">
      <nav class="navigation">.navigation</nav>
      <div class="content">
      <section class="container centered">
      <div class="long-content">.long-content</div>
      </section>
      </div>
      <footer class="footer">.footer</footer>
      </main>





      So, removing display: flex; raised this issue:





      • section within .content does not have the height spanning across .content


      Trying to fix it with position: relative on .content and position: absolute on .centered fixed the height issue but raised:




      • Width of .centered does not span across .content which can be easily fixed with left:0;right:0;

      • Height does not flow with content in section (I'm out of idea here)


      Was it wrong to use position: relative and position: absolute to patch the original issue?
      If so, what is the more suitable solution?






      * { box-sizing: border-box; }
      body { margin: 0; }
      .wrapper {
      display: flex;
      flex-direction: column;
      min-height: 100vh;
      width: 100%;
      background-color: #ccc;
      }
      .navigation {
      background-color: #f00;
      width: 100%;
      height: 3rem;
      }
      .footer {
      background-color: #0f0;
      width: 100%;
      text-align: center;
      line-height: 2rem;
      }

      .content {
      background-color: #ff0;
      flex: 1;
      margin: 0.6rem 0 1.2rem;
      position: relative;
      }
      .container {
      background-color: #f0f;
      margin: 0 auto;
      max-width: 120rem;
      width: 100%;
      padding: 0 2rem;
      }
      .centered {
      display: flex;
      position: absolute;
      height: 100%;
      left: 0;
      right: 0;
      align-items: center;
      justify-content: center;
      }
      .long-content {
      background-color: #fff;
      height: 1000px;
      }

      <main class="wrapper">
      <nav class="navigation">.navigation</nav>
      <div class="content">
      <section class="container centered">
      <div class="long-content">.long-content</div>
      </section>
      </div>
      <footer class="footer">.footer</footer>
      </main>








      * { box-sizing: border-box; }
      body { margin: 0; }
      .wrapper {
      display: flex;
      flex-direction: column;
      min-height: 100vh;
      width: 100%;
      background-color: #ccc;
      }
      .navigation {
      background-color: #f00;
      width: 100%;
      height: 3rem;
      }
      .footer {
      background-color: #0f0;
      width: 100%;
      text-align: center;
      line-height: 2rem;
      }

      .content {
      background-color: #ff0;
      flex: 1;
      margin: 0.6rem 0 1.2rem;
      }
      .container {
      background-color: #f0f;
      margin: 0 auto;
      max-width: 120rem;
      width: 100%;
      padding: 0 2rem;
      }
      .centered {
      display: flex;
      height: 100%;
      align-items: center;
      justify-content: center;
      }
      .long-content {
      background-color: #fff;
      }

      <main class="wrapper">
      <nav class="navigation">.navigation</nav>
      <div class="content">
      <section class="container centered">
      <div class="long-content">.long-content</div>
      </section>
      </div>
      <footer class="footer">.footer</footer>
      </main>





      * { box-sizing: border-box; }
      body { margin: 0; }
      .wrapper {
      display: flex;
      flex-direction: column;
      min-height: 100vh;
      width: 100%;
      background-color: #ccc;
      }
      .navigation {
      background-color: #f00;
      width: 100%;
      height: 3rem;
      }
      .footer {
      background-color: #0f0;
      width: 100%;
      text-align: center;
      line-height: 2rem;
      }

      .content {
      background-color: #ff0;
      flex: 1;
      margin: 0.6rem 0 1.2rem;
      }
      .container {
      background-color: #f0f;
      margin: 0 auto;
      max-width: 120rem;
      width: 100%;
      padding: 0 2rem;
      }
      .centered {
      display: flex;
      height: 100%;
      align-items: center;
      justify-content: center;
      }
      .long-content {
      background-color: #fff;
      }

      <main class="wrapper">
      <nav class="navigation">.navigation</nav>
      <div class="content">
      <section class="container centered">
      <div class="long-content">.long-content</div>
      </section>
      </div>
      <footer class="footer">.footer</footer>
      </main>





      * { box-sizing: border-box; }
      body { margin: 0; }
      .wrapper {
      display: flex;
      flex-direction: column;
      min-height: 100vh;
      width: 100%;
      background-color: #ccc;
      }
      .navigation {
      background-color: #f00;
      width: 100%;
      height: 3rem;
      }
      .footer {
      background-color: #0f0;
      width: 100%;
      text-align: center;
      line-height: 2rem;
      }

      .content {
      background-color: #ff0;
      flex: 1;
      margin: 0.6rem 0 1.2rem;
      position: relative;
      }
      .container {
      background-color: #f0f;
      margin: 0 auto;
      max-width: 120rem;
      width: 100%;
      padding: 0 2rem;
      }
      .centered {
      display: flex;
      position: absolute;
      height: 100%;
      left: 0;
      right: 0;
      align-items: center;
      justify-content: center;
      }
      .long-content {
      background-color: #fff;
      height: 1000px;
      }

      <main class="wrapper">
      <nav class="navigation">.navigation</nav>
      <div class="content">
      <section class="container centered">
      <div class="long-content">.long-content</div>
      </section>
      </div>
      <footer class="footer">.footer</footer>
      </main>





      * { box-sizing: border-box; }
      body { margin: 0; }
      .wrapper {
      display: flex;
      flex-direction: column;
      min-height: 100vh;
      width: 100%;
      background-color: #ccc;
      }
      .navigation {
      background-color: #f00;
      width: 100%;
      height: 3rem;
      }
      .footer {
      background-color: #0f0;
      width: 100%;
      text-align: center;
      line-height: 2rem;
      }

      .content {
      background-color: #ff0;
      flex: 1;
      margin: 0.6rem 0 1.2rem;
      position: relative;
      }
      .container {
      background-color: #f0f;
      margin: 0 auto;
      max-width: 120rem;
      width: 100%;
      padding: 0 2rem;
      }
      .centered {
      display: flex;
      position: absolute;
      height: 100%;
      left: 0;
      right: 0;
      align-items: center;
      justify-content: center;
      }
      .long-content {
      background-color: #fff;
      height: 1000px;
      }

      <main class="wrapper">
      <nav class="navigation">.navigation</nav>
      <div class="content">
      <section class="container centered">
      <div class="long-content">.long-content</div>
      </section>
      </div>
      <footer class="footer">.footer</footer>
      </main>






      html css flexbox






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 16 '18 at 7:03







      josephting

















      asked Nov 16 '18 at 5:49









      josephtingjosephting

      1,71912128




      1,71912128
























          1 Answer
          1






          active

          oldest

          votes


















          0














          I continued looking for solution and quickly noticed that I have shallow knowledge about flexbox itself so I went ahead and played with Flexbox Froggy.



          After completing all the levels, I noticed that I can align everything without position: absolute by just using justify-content on .wrapper.



          Below is my solution for my silly issue.



          If you remove height of .long-content, .centered will continue to get aligned vertically.



          Thank you froggies and shout out to Codepip!






          * { box-sizing: border-box; }
          body { margin: 0; }
          .wrapper {
          display: flex;
          flex-direction: column;
          min-height: 100vh;
          width: 100%;
          background-color: #ccc;
          justify-content: space-between;
          }
          .navigation {
          background-color: #f00;
          width: 100%;
          height: 3rem;
          }
          .footer {
          background-color: #0f0;
          width: 100%;
          text-align: center;
          line-height: 2rem;
          }

          .content {
          background-color: #ff0;
          margin: 0.6rem 0 1.2rem;
          }
          .container {
          background-color: #f0f;
          margin: 0 auto;
          max-width: 120rem;
          width: 100%;
          padding: 0 2rem;
          }
          .centered {
          display: flex;
          height: 100%;
          align-items: center;
          justify-content: center;
          }
          .long-content {
          background-color: #fff;
          height: 1000px;
          }

          <main class="wrapper">
          <nav class="navigation">.navigation</nav>
          <div class="content">
          <section class="container centered">
          <div class="long-content">.long-content</div>
          </section>
          </div>
          <footer class="footer">.footer</footer>
          </main>








          share|improve this answer
























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53332137%2fflexbox-with-center-valign-and-allow-expandable-content%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            I continued looking for solution and quickly noticed that I have shallow knowledge about flexbox itself so I went ahead and played with Flexbox Froggy.



            After completing all the levels, I noticed that I can align everything without position: absolute by just using justify-content on .wrapper.



            Below is my solution for my silly issue.



            If you remove height of .long-content, .centered will continue to get aligned vertically.



            Thank you froggies and shout out to Codepip!






            * { box-sizing: border-box; }
            body { margin: 0; }
            .wrapper {
            display: flex;
            flex-direction: column;
            min-height: 100vh;
            width: 100%;
            background-color: #ccc;
            justify-content: space-between;
            }
            .navigation {
            background-color: #f00;
            width: 100%;
            height: 3rem;
            }
            .footer {
            background-color: #0f0;
            width: 100%;
            text-align: center;
            line-height: 2rem;
            }

            .content {
            background-color: #ff0;
            margin: 0.6rem 0 1.2rem;
            }
            .container {
            background-color: #f0f;
            margin: 0 auto;
            max-width: 120rem;
            width: 100%;
            padding: 0 2rem;
            }
            .centered {
            display: flex;
            height: 100%;
            align-items: center;
            justify-content: center;
            }
            .long-content {
            background-color: #fff;
            height: 1000px;
            }

            <main class="wrapper">
            <nav class="navigation">.navigation</nav>
            <div class="content">
            <section class="container centered">
            <div class="long-content">.long-content</div>
            </section>
            </div>
            <footer class="footer">.footer</footer>
            </main>








            share|improve this answer




























              0














              I continued looking for solution and quickly noticed that I have shallow knowledge about flexbox itself so I went ahead and played with Flexbox Froggy.



              After completing all the levels, I noticed that I can align everything without position: absolute by just using justify-content on .wrapper.



              Below is my solution for my silly issue.



              If you remove height of .long-content, .centered will continue to get aligned vertically.



              Thank you froggies and shout out to Codepip!






              * { box-sizing: border-box; }
              body { margin: 0; }
              .wrapper {
              display: flex;
              flex-direction: column;
              min-height: 100vh;
              width: 100%;
              background-color: #ccc;
              justify-content: space-between;
              }
              .navigation {
              background-color: #f00;
              width: 100%;
              height: 3rem;
              }
              .footer {
              background-color: #0f0;
              width: 100%;
              text-align: center;
              line-height: 2rem;
              }

              .content {
              background-color: #ff0;
              margin: 0.6rem 0 1.2rem;
              }
              .container {
              background-color: #f0f;
              margin: 0 auto;
              max-width: 120rem;
              width: 100%;
              padding: 0 2rem;
              }
              .centered {
              display: flex;
              height: 100%;
              align-items: center;
              justify-content: center;
              }
              .long-content {
              background-color: #fff;
              height: 1000px;
              }

              <main class="wrapper">
              <nav class="navigation">.navigation</nav>
              <div class="content">
              <section class="container centered">
              <div class="long-content">.long-content</div>
              </section>
              </div>
              <footer class="footer">.footer</footer>
              </main>








              share|improve this answer


























                0












                0








                0







                I continued looking for solution and quickly noticed that I have shallow knowledge about flexbox itself so I went ahead and played with Flexbox Froggy.



                After completing all the levels, I noticed that I can align everything without position: absolute by just using justify-content on .wrapper.



                Below is my solution for my silly issue.



                If you remove height of .long-content, .centered will continue to get aligned vertically.



                Thank you froggies and shout out to Codepip!






                * { box-sizing: border-box; }
                body { margin: 0; }
                .wrapper {
                display: flex;
                flex-direction: column;
                min-height: 100vh;
                width: 100%;
                background-color: #ccc;
                justify-content: space-between;
                }
                .navigation {
                background-color: #f00;
                width: 100%;
                height: 3rem;
                }
                .footer {
                background-color: #0f0;
                width: 100%;
                text-align: center;
                line-height: 2rem;
                }

                .content {
                background-color: #ff0;
                margin: 0.6rem 0 1.2rem;
                }
                .container {
                background-color: #f0f;
                margin: 0 auto;
                max-width: 120rem;
                width: 100%;
                padding: 0 2rem;
                }
                .centered {
                display: flex;
                height: 100%;
                align-items: center;
                justify-content: center;
                }
                .long-content {
                background-color: #fff;
                height: 1000px;
                }

                <main class="wrapper">
                <nav class="navigation">.navigation</nav>
                <div class="content">
                <section class="container centered">
                <div class="long-content">.long-content</div>
                </section>
                </div>
                <footer class="footer">.footer</footer>
                </main>








                share|improve this answer













                I continued looking for solution and quickly noticed that I have shallow knowledge about flexbox itself so I went ahead and played with Flexbox Froggy.



                After completing all the levels, I noticed that I can align everything without position: absolute by just using justify-content on .wrapper.



                Below is my solution for my silly issue.



                If you remove height of .long-content, .centered will continue to get aligned vertically.



                Thank you froggies and shout out to Codepip!






                * { box-sizing: border-box; }
                body { margin: 0; }
                .wrapper {
                display: flex;
                flex-direction: column;
                min-height: 100vh;
                width: 100%;
                background-color: #ccc;
                justify-content: space-between;
                }
                .navigation {
                background-color: #f00;
                width: 100%;
                height: 3rem;
                }
                .footer {
                background-color: #0f0;
                width: 100%;
                text-align: center;
                line-height: 2rem;
                }

                .content {
                background-color: #ff0;
                margin: 0.6rem 0 1.2rem;
                }
                .container {
                background-color: #f0f;
                margin: 0 auto;
                max-width: 120rem;
                width: 100%;
                padding: 0 2rem;
                }
                .centered {
                display: flex;
                height: 100%;
                align-items: center;
                justify-content: center;
                }
                .long-content {
                background-color: #fff;
                height: 1000px;
                }

                <main class="wrapper">
                <nav class="navigation">.navigation</nav>
                <div class="content">
                <section class="container centered">
                <div class="long-content">.long-content</div>
                </section>
                </div>
                <footer class="footer">.footer</footer>
                </main>








                * { box-sizing: border-box; }
                body { margin: 0; }
                .wrapper {
                display: flex;
                flex-direction: column;
                min-height: 100vh;
                width: 100%;
                background-color: #ccc;
                justify-content: space-between;
                }
                .navigation {
                background-color: #f00;
                width: 100%;
                height: 3rem;
                }
                .footer {
                background-color: #0f0;
                width: 100%;
                text-align: center;
                line-height: 2rem;
                }

                .content {
                background-color: #ff0;
                margin: 0.6rem 0 1.2rem;
                }
                .container {
                background-color: #f0f;
                margin: 0 auto;
                max-width: 120rem;
                width: 100%;
                padding: 0 2rem;
                }
                .centered {
                display: flex;
                height: 100%;
                align-items: center;
                justify-content: center;
                }
                .long-content {
                background-color: #fff;
                height: 1000px;
                }

                <main class="wrapper">
                <nav class="navigation">.navigation</nav>
                <div class="content">
                <section class="container centered">
                <div class="long-content">.long-content</div>
                </section>
                </div>
                <footer class="footer">.footer</footer>
                </main>





                * { box-sizing: border-box; }
                body { margin: 0; }
                .wrapper {
                display: flex;
                flex-direction: column;
                min-height: 100vh;
                width: 100%;
                background-color: #ccc;
                justify-content: space-between;
                }
                .navigation {
                background-color: #f00;
                width: 100%;
                height: 3rem;
                }
                .footer {
                background-color: #0f0;
                width: 100%;
                text-align: center;
                line-height: 2rem;
                }

                .content {
                background-color: #ff0;
                margin: 0.6rem 0 1.2rem;
                }
                .container {
                background-color: #f0f;
                margin: 0 auto;
                max-width: 120rem;
                width: 100%;
                padding: 0 2rem;
                }
                .centered {
                display: flex;
                height: 100%;
                align-items: center;
                justify-content: center;
                }
                .long-content {
                background-color: #fff;
                height: 1000px;
                }

                <main class="wrapper">
                <nav class="navigation">.navigation</nav>
                <div class="content">
                <section class="container centered">
                <div class="long-content">.long-content</div>
                </section>
                </div>
                <footer class="footer">.footer</footer>
                </main>






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 16 '18 at 6:20









                josephtingjosephting

                1,71912128




                1,71912128
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53332137%2fflexbox-with-center-valign-and-allow-expandable-content%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Florida Star v. B. J. F.

                    Danny Elfman

                    Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues