adrianmanuel adrianmanuel - 5 months ago 10
Javascript Question

Text div over image resizable

I wonder if there is any way to put text inside a div over an image, i know can use z-index, but I need the text gets smaller as the size of the image. thanks for everything i want to resizable the textbox with the image

Answer

Here is one way, using viewport units vw

div {
  position: relative;
  width: 30vw;
  height: 30vw;
}
div img {
  display: inline-block;
  width: 100%;
  height: 100%;
}
div span {
  position: absolute;
  left: 0;
  top: 0;
  font-size: 6vw;
  color: red;
  font-weight: bold;
}
<div>
  <img src="http://lorempixel.com/200/200/animals" alt="">
  <span>Hey there</span>
</div>