HTML Element Style How to - Create column layout with various div height








Question

We would like to know how to create column layout with various div height.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.wrapper {<!--from w  w  w.  jav a  2  s  . c  o m-->
  column-count: 2;
  column-width: 100px;
  -moz-column-width: 100px;
  -webkit-column-width: 100px;
  width: 260px;
}

div {
  border: 1px solid #999;
  display: inline-block;
  margin: 10px;
  width: 100px;
}

.block1 {
  height: 100px;
}

.block2 {
  height: 130px;
}

.block3 {
  height: 150px;
}

.block4 {
  height: 100px;
}

.block5 {
  height: 120px;
}

.block6 {
  height: 100px;
}

.block7 {
  height: 120px;
}

.block8 {
  height: 160px;
}
</style>
</head>
<body>
  <div class="wrapper">
    <div class="block1">1</div>
    <div class="block3">3</div>
    <div class="block4">5</div>
    <div class="block5">7</div>
    <div class="block2">2</div>
    <div class="block6">4</div>
    <div class="block7">6</div>
    <div class="block8">8</div>
  </div>
</body>
</html>

The code above is rendered as follows: