HTML Element Style How to - Center two images with text-align: center; and vertical-align: middle;








Question

We would like to know how to center two images with text-align: center; and vertical-align: middle;.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.image_container {<!--  w w  w . j  a va  2 s  .  c o m-->
  width: 50%;
  height: 300px;
  line-height: 300px;
  background: #eee;
  text-align: center;
  float: left;
}

.image_container img {
  vertical-align: middle;
}
</style>
</head>
<body>
  <div class="image_container">
    <image src="http://www.java2s.com/style/download.png" height="100" width="100"/>
  </div>
  <div class="image_container">
    <image src="http://www.java2s.com/style/download.png" height="100" width="100" />
  </div>
</body>
</html>

The code above is rendered as follows: