HTML Element Style How to - Extending the width of a sub-div to 100%








Question

We would like to know how to extending the width of a sub-div to 100%.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.SubDIV {<!--from ww  w  .  j  ava  2 s.  c  o  m-->
  position: absolute;
  top: 50px;
  background: #EEE;
  width: 100%;
}

.MainContainerDIV {
  background: #AAA;
}
</style>
</head>
<body>
  <div class="MainContainerDIV" style="width: 300px; height: 200px;">
    This is the main div
    <div class="SubDIV">
      <p>this is the sub div</p>
    </div>
  </div>
</body>
</html>

The code above is rendered as follows: