When creating a photo gallery or something like that you might need to place some caption text or description over the image. You can use the CSS positioning methods in combination with the margin property to position or place the text over an image (i.e. the
Your text here
0 with a class named “image-container” and add an image within it. Next, create another
Your text here
0 with a class named “overlay-text” and add your text inside.
Your text here
We know that in real-life scenarios, it’s unlikely for a web page to contain an image only. However, we’ll do this in this tutorial for the sake of simplicity. No matter if you’re overlaying the text on a banner, product image, or any other type of image on your website, it works similarly.
When you open the HTML file in a browser, it should look like this:
Next, we are going to style the page using CSS to overlay the text on the image. Create a CSS file named “style.css” and add a
Your text here
2 tag in the head section of the HTML file to link these two files.