- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to place text blocks over an image using CSS?
Following is the code to produce text blocks over an image using CSS −
Example
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> .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; } </style> </head> <body> <h1>Image Text Block Example</h1> <div class="imageContainer"> <img src="https://i.picsum.photos/id/59/500/500.jpg" alt="Nature" style="width:100%;"> <div class="captionBlock"> <h3>Scenary</h3> <h4>Fence on the ground</h4> </div> </div> </body> </html>
Output
The above code will produce the following output −
Advertisements