CSS Layout How to - Align child to left top corner of parent








Question

We would like to know how to align child to left top corner of parent.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
#first {<!--from   w ww.j  a  v  a  2  s  .c om-->
  width: 200px;
  height: 100px;
  background-color: blue;
}

#second {
  width: 100px;
  height: 50px;
  background-color: red;
}
</style>
</head>
<body>
  <div id="first">
    <div id="second">
      <div id="third">Nested Div's</div>
    </div>
  </div>
</body>
</html>

The code above is rendered as follows: