HTML Element Style How to - Center an image vertically within a line of text








Question

We would like to know how to center an image vertically within a line of text.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.cv {<!-- ww w.  j  a va 2  s.  c  o  m-->
  line-height: 1.4em;
}

.cv a {
  text-decoration: none;
  color: #999;
}

.cv img {
  vertical-align: middle;
  margin-right: 10px;
}

.cv a:hover {
  color: #333;
}
</style>
</head>
<body>
  <p class="cv">
    <a href=""> <img
      src="http://www.java2s.com/style/download.png" />
      Download CV.
    </a>
  </p>
</body>
</html>

The code above is rendered as follows: