HTML Element Style How to - Vertical Align Image inside DIV








Question

We would like to know how to vertical Align Image inside DIV.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
#block {<!--   w  w  w. j a  va2 s  .c om-->
  width: 348px;
  display: table;
  background-color: lightblue; 
}

#content {
  width: 164px;
  padding: 20px;
}

#image {
  width: 144px;
  display: table-cell;
  vertical-align: middle;
}
</style>
</head>
<body>
  <div id="block">
    <div id="content">Some content goes here.</div>
    <div id="image">
      <img src="http://placehold.it/20x20" />
    </div>
  </div>
</body>
</html>

The code above is rendered as follows: