CSS Layout How to - Float in the same lines








Question

We would like to know how to float in the same lines.

Answer


<!DOCTYPE html>
<html lang="en">
<head>
<title>Example of CSS floating</title>
<style type="text/css">
div {<!--  ww w  .  jav  a 2  s . c  om-->
  width: 200px;
  padding: 10px;
}

div.red {
  float: left;
  background: #ff0000;
}

div.green {
  float: right;
  background: #00ff00;
}
</style>
</head>
<body>
  <div class="red">Floated to left.</div>
  <div class="green">Floated to right.</div>
</body>
</html>

The code above is rendered as follows: