It was not as difficult as thought it would be. Using CSS I could achieve what I planned, and it is simple. I’ll share this with you.
Here’s what I would do to get the result. I need a DIV element that will serve as a container and a <span> element that will have the text, which I want to show.
First, add the DIV element on your web page and assign the image as the background. Since, it serves as a container any other element you add, will rest on top of the background image. All we need then is to position the element with text, at the bottom of the DIV and create a transparent view of the text.
<!doctype html> <html> <head> <title>Text Over Image with CSS</title> <style> body { margin:2px; padding:0; } .myImage { font:14px Verdana; background:url('image.jpg'); width:706px; height:209px; } </style> </head> <body> <div class="myImage"> <span>A Text over an image</span> </div> </body> </html>
We now have the div showing an image as background and a text over it. As expected, it will show the text at the top location inside the DIV. I want the text at the bottom, with transparent effect. Therefore, I’ll add some CSS properties to the <span>.
span { display:block; background:#000; background:rgba(0, 0, 0, 0.6); color:#FFF; padding:20px 5px; }
I have now added a darkish, transparent background to the text. The CSS rgba() method takes 4 parameters. The first three Zeros will return the color black and the last parameter 0.6 is for opacity, to give the element a transparent look.
Finally, I’ll set the position of the <span> along with <div> element. I’ll set the DIV’s position as “relative” and the <span> as absolute (so I can move it anywhere I want inside the container), with its ‘bottom’, ‘left’ and ‘right’ property set as 0.
<!doctype html> <html> <head> <title>Text Over Image with CSS</title> <style> body { margin:2px; padding:0; } .myImage { font:14px Verdana; background:url('image.jpg'); width:565px; height:167px; position:relative; } span { display:block; position:absolute; bottom:0; left:0; right:0; background:#000; background:rgba(0, 0, 0, 0.6); color:#FFF; padding:20px 5px; } </style> </head> <body> <div class="myImage"> <span> A Text over an image. <a href="#" style="color:#FD9C00;text-decoration:none;">See more examples.</a> </span> </div> </body> </html>
👉 Do you know you can add a transparent text to an iamge (anywhere on the image) and save the image?Check out this article.