CSS Layout How to - Align div tags to the top of their parent








Question

We would like to know how to align div tags to the top of their parent.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.tripple {<!--from w  w w.j  a v a 2  s . c o  m-->
  width: 90%;
  height: 100%;
  margin: 5%;
  border: solid;
}

.clearfix:before, .clearfix:after {
  content: " "; /* 1 */
  display: table; /* 2 */
}

.clearfix:after {
  clear: both;
}

.left, .right, .middle {
  float: left;
  width: 33%;
  height: 100px;
}

.left {
  background-color: red;
}

.middle {
  background-color: green;
}

.right {
  background-color: blue;
}
</style>
</head>
<body>
  <div class="tripple clearfix">
    <div class="left">test</div>
    <div class="middle">test</div>
    <div class="right">test</div>
  </div>
</body>
</html>

The code above is rendered as follows: