CSS Layout How to - Create a table-like layout with fluid positioning








Question

We would like to know how to create a table-like layout with fluid positioning.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
#wrapper {<!--  w  w  w .  ja v  a  2  s .  co  m-->
  width: 360px;
  height: 220px;
  margin-left: -20px;
}

.box {
  float: left;
  height: 100px;
  width: 100px;
  margin-left: 20px;
  margin-bottom: 20px;
  background: #f00;
}
</style>
</head>
<body>
  <div id="wrapper">
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
  </div>
</body>
</html>

The code above is rendered as follows: