How to place text blocks over an image using CSS?

CSSWeb DevelopmentFront End Technology

Following is the code to produce text blocks over an image using CSS −


 Live Demo

<!DOCTYPE html>
<meta name="viewport" content="width=device-width, initial-scale=1">
.imageContainer {
   display: inline-block;
   position: relative;
   font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif
.captionBlock {
   position: absolute;
   bottom: 20px;
   right: 20px;
   background-color: rgb(14, 0, 94);
   color: rgb(255, 255, 255);
   padding-left: 20px;
   padding-right: 20px;
   font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
<h1>Image Text Block Example</h1>
<div class="imageContainer">
<img src="" alt="Nature" style="width:100%;">
<div class="captionBlock">
<h4>Fence on the ground</h4>


The above code will produce the following output −

Published on 06-Apr-2020 16:27:48