CSS Layout How to - Layout Dynamic number of cells on fixed number of columns








Question

We would like to know how to layout Dynamic number of cells on fixed number of columns.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.container_4 {<!--  w  w w  . ja  v a  2 s .com-->
  width: 480px;
  height: 160px;
  background: #EFEFEF;
}

.cell {
  border: solid 1px #999;
  float: left;
  height: 58px;
  margin-left: 10px;
  margin-top: 10px;
  width: 98px;
  background-color: White;
}
</style>
</head>
<body>
  <div class="container_4">
    <div class="cell">Cell 1</div>
    <div class="cell">Cell 2</div>
    <div class="cell">Cell 3</div>
    <div class="cell">Cell 4</div>
    <div class="cell">Cell 5</div>
    <div class="cell">Cell 6</div>
    <div class="cell">Cell 7</div>
  </div>
</body>
</html>

The code above is rendered as follows: