JSFiddle - React, Tailwind, and code Playground

by Ulrich Bangert

HTML

<h2>
Text above image
</h2>
<p>
Text is positioned absolutely above the image<br>
Pro: Container adjusts it's size to the image, thus the configuration can be made responsive easily<br>
Con: Aligning the text is a bit more komplex
</p>
<figure id="container2">
  <img src="https://webentwicklung.ulrichbangert.de/images/burgtor_01.jpg">
  <figcaption id="inner2">
    Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
  </figcaption>
</figure>

CSS

html, body {
  width: 100%;
}

body, figure {
  margin: 0;
}

body {
  display: flex;
  flex-direction: column;
}

#container2 {
  border: 2px solid blue;
  max-width: 800px;
}

#inner2 {
  width: 80%;
  text-align: center;
}

#container2 {
  position: relative;
  display: inline-block;
}

#container2>img {
  width: 100%;
  height: auto;
}

#inner2 {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

#container2 img {
  vertical-align: top;
}