HTML Element Style How to - Make Parent div's height is larger than his children








Question

We would like to know how to make Parent div's height is larger than his children.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
#div1 {<!-- w  w w  .  j  a  v  a2s.c  om-->
  background-color: red;
  margin: 10;
  padding: 10;
  text-align: justify;
}

#div1 #span1 {
  display: inline-block;
  width: 100%;
  background-color: #EEE;
}

#div1 #span2 {
  width: 100%;
  height: 0px;
  background-color: #AAA;
}
</style>
</head>
<body>
  <div id="div1">
    <span id="span1">ABC DEF GHI JKL</span> 
    <span id="span2">this is a test</span>
  </div>
</body>
</html>

The code above is rendered as follows: