CSS Layout How to - Position absolute top property based on the parent width








Question

We would like to know how to position absolute top property based on the parent width.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.child-of-body {<!--from w  w  w . ja  v a2s.  c om-->
  position: absolute;
  margin-top: 10%;
}
</style>
</head>
<body>
  <div class="child-of-body">This is a text</div>
</body>
</html>

The code above is rendered as follows: