HTML Element Style How to - Overlay text and image








Question

We would like to know how to overlay text and image.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.image {<!--  w  ww.j a  va 2  s  .  c  o m-->
  position: relative;
}

.wrapper {
  position: absolute;
  top: 50%;
  left: 0;
}

h2 {
  margin: 0;
  padding: 0;
}
</style>
</head>
<body>
  <div class="image">
    <img src="http://www.java2s.com/style/download.png" />
    <div class="wrapper">
      <h2>Title</h2>
    </div>
  </div>
</body>
</html>

The code above is rendered as follows: