CSS Layout How to - Position two divs one the left and right








Question

We would like to know how to position two divs one the left and right.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
#parent {<!--from w  w w .  j  av  a2 s  .c o m-->
  width: 600px; height; 100 px;
  background: red;
  overflow: hidden;
}

#one {
  width: 100px;
  float: left;
  height: 100px;
  background: blue;
}

#two {
  width: 100px;
  float: right;
  height: 100px;
  background: green;
}
</style>
</head>
<body>
  <div id="parent">
    <div id="one"></div>
    <div id="two"></div>
  </div>
</body>
</html>

The code above is rendered as follows: