CSS Layout How to - Vertically centered image








Question

We would like to know how to vertically centered image.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.body_splash {<!--from   ww  w  .j a v  a 2 s .co  m-->
  width: 378px;
  float: left;
  height: 400px;
  background-color: #eaeaea;
  position: relative;
}

.body_splash img {
  position: absolute;
  left: 154px;
  top: 164px
}
</style>
</head>
<body>
  <div class="body_splash">
    <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/a/a3/Cc.logo.circle.svg/64px-Cc.logo.circle.svg.png"
      width="64" height="64" />
  </div>
</body>
</html>

The code above is rendered as follows: