1

I have a simple layout: header + sidebar + content + footer.

The root element has a flex display with row direction; root = sidebar + wrapper. The wrapper = header + content + footer. The wrapper is displayed as flex and has flex direction of column.

When the content is a single word, the footer is visible just fine, however once I replace the content with a lot of text, the footer disappears (pics below).

JsFiddle with little content: https://jsfiddle.net/3mfdu8ey/1/

enter image description here

JsFiddle with a lot of content: https://jsfiddle.net/3mfdu8ey/2/

enter image description here

And once I scroll the second fiddle to the end:

enter image description here

The footer is gone. I tried fixing it with

  height: calc(100vh - 200);  

on #content-wrapper, but it didn't work.

My code:

html:

 <div id = "app">
    <div id = "custom-sidebar">
      Sidebar
    </div>

    <div id = "content-wrapper">
      <div id = "header">
        Header
      </div>

      <div id = "content">
        Content
      </div>

      <div id = "footer">
      Footer
      </div>
    </div>
  </div>

css:

#content-wrapper  {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  width: 100%;
  height: calc(100vh - 200);  
 }

#content  {
  padding: 30px;
}

#app  {
  background-color: gray;
  display: flex;
  height: 100vh;
  font-family: 'Source Sans Pro', sans-serif;
  padding: 0;
}

 #header  {
        width: 100%;
        display: flex;
        flex-direction: column;
        justify-content: center;
         align-items: flex-end;
        padding-bottom: 20px;
}

#sidebar  {
    width: 12%;
    float: left;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }

 #footer  {
        height: 200px;
        width: 100%;
    }

/*
  Colors
*/

#custom-sidebar  {
 background-color: orange;
}

#footer  {
  background-color: green;
}

#header  {
  background-color: red;
}

#content  {
  background-color: silver;
}
parsecer
  • 4,758
  • 13
  • 71
  • 140

1 Answers1

1

You need to set overflow on your content to prevent it from pushing footer down. See my example.

Edit: You need to set min-height instead of height. See this fiddle: https://jsfiddle.net/z9qt1cwr/

I include the minimal amount of styles you'll need to achieve this.

body,
html {
  margin: 0;
  box-sizing: border-box;
}

#app {
  display: flex;
  min-height: 100vh;
}


#content-wrapper {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  width: 100%;

}

#custom-sidebar {
  width: 12%;
}

#content {}

#header {}

#footer {
  height: 200px;
}

#custom-sidebar, #header, #content, #footer {
  padding: 1rem 2rem;
}

/*
  Colors
*/


#app {
  background-color: gray;
}

#custom-sidebar {
  background-color: orange;
}

#footer {
  background-color: green;
}

#header {
  background-color: red;
}

#content {
  background-color: silver;
}