[html] Css height in percent not working

I have the following simple code:

_x000D_
_x000D_
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">_x000D_
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">_x000D_
_x000D_
<head>_x000D_
  <title>Live Feed</title>_x000D_
_x000D_
  <meta http-equiv="content-type" content="text/html; charset=UTF-8" />_x000D_
_x000D_
  <style>_x000D_
    body {_x000D_
      margin: 0px;_x000D_
      padding: 0px;_x000D_
    }_x000D_
  </style>_x000D_
</head>_x000D_
_x000D_
<body>_x000D_
  <div style="background-color: #eeaabb; width: 250px; height: 100%; border-right: solid 1px #e1e1e1;">_x000D_
    I should be tall_x000D_
  </div>_x000D_
</body>_x000D_
_x000D_
</html>
_x000D_
_x000D_
_x000D_

But the div doesn't get displayed with height being 100%. Why?

This question is related to html css

The answer is


Make it 100% of the viewport height:

div {
  height: 100vh;
}

Works in all modern browsers and IE>=9, see here for more info.


the root parent have to be in pixels if you want to work freely with percents,

<body style="margin: 0px; width: 1886px; height: 939px;">
<div id="containerA" class="containerA" style="height:65%;width:100%;">
    <div id="containerAinnerDiv" style="position: relative; background-color: aqua;width:70%;height: 80%;left:15%;top:10%;">
       <div style="height: 100%;width: 50%;float: left;"></div>
       <div style="height: 100%;width: 28%;float:left">
            <img src="img/justimage.png" style="max-width:100%;max-height:100%;">
       </div>
       <div style="height: 100%;width: 22%;float: left;"></div>
    </div>
</div>
</body>

height: 100% works if you give a fixed size to the parent element.


You need to set 100% height on the parent element.


You can achieve that by using positioning.

Try

position: absolute;

to get the 100% height.


This is what you need in the CSS:

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

Add height:100% to body

body{height:100%}