0

I have a header a main and a footer. The the header and the foter have fixed heights. The main has a min-height of 100% - 250px(header + footer). I want to extend the div id="content" inside the main to the full height of the main. Why isn't it working?

html {
  height: 100%;
  box-sizing: border-box;
}

*,
*:before,
*:after {
  box-sizing: inherit;
}

body {
  background-color: #f5f5f5;
  margin: 0;
  padding: 0;
  position: relative;
  height: 100%;
}

header {
  background-color: #131b23;
  border-bottom: 6px solid #0f151a;
  text-align: center;
  left: 0;
  top: 0;
  width: 100%;
  height: 170px;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23);
  z-index: 99;
}

main {
  text-align: center;
  min-height: calc(100% - 250px);
  /* Header 170px + Footer 80px = 250px */
  background-color: blue;
}

#content {
  width: 65%;
  margin-left: auto;
  margin-right: auto;
  background-color: red;
  min-height: 100%;
}

footer {
  background-color: #131b23;
  border-top: 6px solid #0f151a;
  text-align: center;
  height: 80px;
  z-index: 98;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23);
  width: 100%;
}
<header>
</header>

<main>
  <div id="content">
    Text 123
  </div>
</main>

<footer>
</footer>
Stickers
  • 75,527
  • 23
  • 147
  • 186
Noah Adler
  • 19
  • 2
  • Possible duplicate of [how to make DIV height 100% between header and footer](https://stackoverflow.com/questions/10228280/how-to-make-div-height-100-between-header-and-footer) – Nihal Feb 11 '18 at 15:48
  • add 1px height to main and it will work ! – Temani Afif Feb 11 '18 at 15:53
  • well i will avoid to close this one fastly, but here is some related question : https://stackoverflow.com/questions/16043519/nested-min-height-does-not-work – Temani Afif Feb 11 '18 at 16:02
  • https://stackoverflow.com/questions/7049875/height-100-not-working – Temani Afif Feb 11 '18 at 16:02

3 Answers3

1

min-height will work if parent has defined height as height in percentage is relative to parent.

In your case, parent of content div is main and main has min-height : calc(100% - 250px) and not height. Change min-height to height for main.

h3t1
  • 1,126
  • 2
  • 18
  • 29
-1

use this css to set height of content to 100%

#content {
  width: 65%;
  margin-left: auto;
  min-height:100%;  
   margin-right: auto;
  background-color: red;

}

snippet

html,body {
  height: 100%;
  box-sizing: border-box;
}

*,
*:before,
*:after {
  box-sizing: inherit;
}

body {
  background-color: #f5f5f5;
  margin: 0;
  padding: 0;
  position: relative;
  height: 100%;
}
main {
  text-align: center;
 
   min-height: calc(100% - 250px);

  /* Header 170px + Footer 80px = 250px */
  background-color: blue;
}
header {
  background-color: #131b23;
  border-bottom: 6px solid #0f151a;
  text-align: center;
  left: 0;
  top: 0;
  width: 100%;
  height: 170px;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23);
  z-index: 99;
}
#content {
  width: 65%;
  margin-left: auto;
 min-height:100%; 
   margin-right: auto;
  background-color: red;
  
}

footer {
  background-color: #131b23;
  border-top: 6px solid #0f151a;
  text-align: center;
  height: 80px;
  z-index: 98;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23);
  width: 100%;
}
<header>

</header>

<main id=mai >
  <div id="content" style="height:100px">
    Text 123Text 123Text 123Text 123Text 123
  </div>
</main>

<footer>

</footer>
<style>

</style>

Why is the height 100% not working?

because height of main content is set to 100% which means set height of content in which to fit all info in content .

jasinth premkumar
  • 1,430
  • 1
  • 12
  • 22
-1

This works as long as the page is taller than the content. You might need to display the result in full page view.

html {
  height: 100%;
  box-sizing: border-box;
}

*,
*:before,
*:after {
  box-sizing: inherit;
}

body {
  background-color: #f5f5f5;
  margin: 0;
  padding: 0;
  position: relative;
  height: 100%;
}

header {
  background-color: #131b23;
  border-bottom: 6px solid #0f151a;
  text-align: center;
  left: 0;
  top: 0;
  width: 100%;
  height: 170px;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23);
  z-index: 99;
}

main {
  text-align: center;
  min-height: calc(100% - 250px);
  /* Header 170px + Footer 80px = 250px */
  background-color: blue;
position:relative;
}

#content {
  width: 65%;
  margin-left: 17.5%;
  margin-right: 17.5%;
  background-color: red;
  height: 100%;
position:absolute
}

footer {
  background-color: #131b23;
  border-top: 6px solid #0f151a;
  text-align: center;
  height: 80px;
  z-index: 98;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23);
  width: 100%;
}
<header>

</header>

<main>
  <div id="content">
    Text 123
  </div>
</main>

<footer>

</footer>
</body>

</html>
Lukas T
  • 116
  • 2
  • 8