CSS Layout How to - Create Empty relative div with a fixed size








Question

We would like to know how to create Empty relative div with a fixed size.

Answer


<!DOCTYPE html>
<html>
<head>
</head><!--from   www . j  av  a 2 s  .com-->
<body>
  <div style="height: 500px; width: 500px;">
    <div style="position: relative; width: 10%; height: 20%; background-color: red;">My div</div>
  </div>
</body>
</html>

The code above is rendered as follows: