HTML Element Style How to - Position div with inline-block








Question

We would like to know how to position div with inline-block.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
#nav {<!--from   w w w.j ava 2  s .c  o  m-->
  position: absolute;
  top: 0;
  right: 0;
}

#nav div {
  width: 120px;
  height: 40px;
  display: inline-block;
  vertical-align: bottom;
}

#nav div+div {
  margin-left: 10px;
}

.red {
  background-color: #f00;
}

.green {
  background-color: #0f0;
}

.blue {
  background-color: #00f;
}
</style>
</head>
<body>
  <div id="nav">
    <div class="red"></div>
    <div class="green"></div>
    <div class="blue"></div>
  </div>
</body>
</html>

The code above is rendered as follows: