Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to put text over images in html?

Tags:

html

How to put text over images in HTML. Everytime I enter the below code, the text goes under the image.

<img src="example.jpg">Text</img> 
like image 474
user719813 Avatar asked Apr 22 '11 18:04

user719813


People also ask

How do I put text over an image in HTML?

CSS position property is used to set the position of text over an image. This can be done by enclosing the image and text in an HTML “div”. Then make the position of div “relative” and that of text “absolute”.

How do you put text over an image?

On the Insert tab, in the Text group, click Text Box, click anywhere near the picture, and then type your text. To change the font or style of the text, highlight the text, right-click it, and then select the text formatting you want on the shortcut menu.

How do I display text under an image in HTML?

The <figcaption> tag defines a caption for a <figure> element. The <figcaption> element can be placed as the first or last child of the <figure> element.

How do I put text over an image in HTML bootstrap?

Add class=carousel-caption to the HTML tag which contains your text which needs to be positioned over your image !. (And then if you wish add custom css top:xyz% to your . carousel-caption class in css stylesheet to make it align vertically at middle.)


2 Answers

You can create a div with the exact same size as the image.

<div class="imageContainer">Some Text</div> 

use the css background-image property to show the image

 .imageContainer {        width:200px;         height:200px;         background-image: url(locationoftheimage);  } 

more here

note: this slichtly tampers the semantics of your document. If needed use javascript to inject the div in the place of a real image.

like image 77
Caspar Kleijne Avatar answered Sep 21 '22 20:09

Caspar Kleijne


You need to use absolutely-positioned CSS over a relatively-positioned img tag. The article Text Blocks Over Image gives a step-by-step example for placing text over an image.

like image 27
kevinji Avatar answered Sep 19 '22 20:09

kevinji