CSS Layout How to - Stack inline block elements








Question

We would like to know how to stack inline block elements.

Answer


<!--from ww w . j  av a  2s .c om-->
<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.img-block {
  max-width: 50px;
  max-height: 50px;
}

.div-block {
  display: inline-block;
}

.img-container {
  width: 250px;
  margin: 0 auto;
  background-color: red;
}
</style>
</head>
<body>
  <div class="img-container">
    <div class="div-block">
      <img class="img-block"
        src="http://www.java2s.com/style/download.png" />
    </div>
    <div class="div-block">
      <img class="img-block"
        src="http://www.java2s.com/style/download.png" />
    </div>
    <div class="div-block">
      <img class="img-block"
        src="http://www.java2s.com/style/download.png" />
    </div>
    <div class="div-block">
      <img class="img-block"
        src="http://www.java2s.com/style/download.png" />
    </div>
    <div class="div-block">
      <img class="img-block"
        src="http://www.java2s.com/style/download.png" />
    </div>
    <div class="div-block">
      <img class="img-block"
        src="http://www.java2s.com/style/download.png" />
    </div>
    <div class="div-block">
      <img class="img-block"
        src="http://www.java2s.com/style/download.png" />
    </div>
    <div class="div-block">
      <img class="img-block"
        src="http://www.java2s.com/style/download.png" />
    </div>
    <div class="div-block">
      <img class="img-block"
        src="http://www.java2s.com/style/download.png" />
    </div>
  </div>
</body>
</html>

The code above is rendered as follows: