CSS Layout How to - Divs on same line fill the rest of width








Question

We would like to know how to divs on same line fill the rest of width.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
#container {<!-- w  w  w  .j a v a  2 s  .  c o  m-->
  width: 100%;
}

#div1 {
  width: 100px;
  float: left;
  border: 1px solid;
}

#div2 {
  border: 1px solid;
}
</style>
</head>
<body>
  <div id="container">
    <div id="div1">div 1</div>
    <div id="div2">div 2</div>
  </div>
</body>
</html>

The code above is rendered as follows: