CSS Layout How to - Float to fit in single line








Question

We would like to know how to float to fit in single line.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
#wrapper {<!--from  w  w  w  .  j  ava 2s.  c o m-->
  border: 2px solid red;
  overflow: hidden;
}

#col1 {
  width: 20%;
  float: left;
  background-color: grey;
}

#col2 {
  width: 50%;
  float: left;
  background-color: green;
}

#col3 {
  width: 30%;
  float: left;
  background-color: yellow;
}
</style>
</head>
<body>
  <div id="wrapper">
    <div id="col1">Column 1</div>
    <div id="col2">Column 2</div>
    <div id="col3">Column 3</div>
  </div>
</body>
</html>

The code above is rendered as follows: