CSS Layout How to - Fit elements in 100% width div








Question

We would like to know how to fit elements in 100% width div.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
#div1 {<!--from   www. jav a 2s  .com-->
  width: 200px;
  height: 100px;
  background-color: #EEE;
  float: left;
}

#div2 {
  width: 200px;
  height: 100px;
  background-color: #DDD;
  float: right;
}

#div3 {
  width: auto;
  height: 100px;
  background-color: #AAA;
  margin: 0 200px;
}
</style>
</head>
<body>
  <div id="div1"></div>
  <div id="div2"></div>
  <div id="div3"></div>
</body>
</html>

The code above is rendered as follows: