1

I have a parent section with a min-height css of 100%. The child is a div with height: 100%;. But the child div does not occupy the whole parent section

What I'm trying to achieve is the child will occupy the space.

html,
body {
  height: 100%;
  width: 100%;
  padding: 0px;
  margin: 0px;
}

div {
  box-sizing: border-box;
}

.container {
  width: 100%;
  min-height: 100%;
  background-color: red;
}

.content {
  width: 100%;
  height: 100%;
  background-color: blue;
}
<section class="container">
  <div class="content">
    HEY!
  </div>
</section>

3 Answers3

1

html,
body {
  height: 100%;
  width: 100%;
  padding: 0px;
  margin: 0px;
}

div {
  box-sizing: border-box;
}

.container {
  width: 100%;
  height: 100%;
  background-color: red;
  display: block;
}

.content {
  width: 100%;
  min-height: 100%;
  background-color: blue;
  display: block;
}
#child1 { 
  background-color: blue; 
}

#child2 { 
  background-color: yellow; 
}
<section class="container">
  <div class="content" id="child1">
    HEY Child 1 See Child 2 down!
  </div>
  <div class="content" id="child2">
    HEY Child 2!
  </div>
</section>
Giddy Naya
  • 4,237
  • 2
  • 17
  • 30
  • I have to use min-height there are other child element. I just want the .content to be have the same height with the window –  Jul 29 '19 at 08:14
0

just add position:absolute to the child element.

If you want the parent element to be relative then add position:relative to parent element.

Relative Position: A relative positioned element is positioned relative to its normal position.

To know more about relative and absolute position visit:Difference between style = "position:absolute" and style = "position:relative"

     html,
    body {
      height: 100%;
      width: 100%;
      padding: 0px;
      margin: 0px;
    }

    div {
      box-sizing: border-box;
    }

    .container {
      width: 100%;
      min-height: 100%;
      background-color: red;
    }

    .content {
      width: 100%;
      height: 100%;
      color:white;   
      position: absolute;   
      background-color: blue;   
    }
  <section class="container">    
      <div class="content">    
        HEY!   
      </div>   
    </section>    
Amaresh S M
  • 2,936
  • 2
  • 13
  • 25
0

You should try this :

Just add

position: absolute;

in child css class.

html,
body {
  height: 100%;
  width: 100%;
  padding: 0px;
  margin: 0px;
}

div {
  box-sizing: border-box;
}

.container {
  width: 100%;
  min-height: 100%;
  background-color: red;  
}

.content {
  width: 100%;
  height: 100%;
  background-color: blue;
  position: absolute;
}
<section class="container">
  <div class="content">
    HEY!
  </div>
</section>