How To Add Text Blocks Over An Image

I want to lớn vì chưng something like the one below but I"m having difficulties, here"s my current css


When I use background-image I bởi not get any output from html2pdf:



How about something lượt thích this:

Its done by using position:absolute và z-index to place the text over the image.

Bạn đang xem: How to add text blocks over an image

#container height: 400px; width: 400px; position: relative;#image position: absolute; left: 0; top: 0;#text z-index: 100; position: absolute; color: white; font-size: 24px; font-weight: bold; left: 150px; top: 350px;

Hello World!


This is another method for working with Responsive sizes. It will keep your text centered and maintain its position within its parent. If you don"t want it centered then it"s even easier, just work with the absolute parameters. Keep in mind the main container is using display: inline-block. There are many others ways lớn vì chưng this, depending on what you"re working on.

Based off of Centering the Unknown

Working codepen example here




.containerBox position: relative; display: inline-block;.text-box position: absolute; height: 100%; text-align: center; width: 100%;.text-box:before content: ""; display: inline-block; height: 100%; vertical-align: middle;h4 display: inline-block; font-size: 20px; /*or whatever you want*/ color: #FFF; img display: block; max-width: 100%; height: auto;


Why not phối sample.png as background image of text or h2 css class? This will give effect as you have sầu written over an image.

Xem thêm:

For a responsive thiết kế it is good lớn use a container having a relative layout & nội dung (placed in container) having fixed layout as.

CSS Styles:

/*Centering element in a base container*/.contianer-relative position: relative; .content-center-text-absolute position: absolute; text-align: center; width: 100%; height: 0%; margin: auto; top: 0; left: 0; bottom: 0; right: 0; z-index: 51;HTML code:

For IONIC Grid layout, evenly spaced grid elements and the classes used in above sầu HTML, please refer - Grid: Evenly Spaced Columns. Hope it helps you out... :)

as Harry Joy points out, set the image as the div"s background and then, if you only have one line of text you can mix the line-height of the text khổng lồ be the same as the div height và this will place your text in the center of the div.

If you have sầu more than one line you"ll want khổng lồ mix the display to be table-cell và vertical-alignment to lớn middle.

as of 2017 this is more responsive và worked for me.This is for putting text inside vs over, lượt thích a badge.instead of the number 8, I had a variable khổng lồ pull data from a database.

this code started with Kailas"s answer up above


& my css:

.containerBox position: relative; display: inline-block;.text-box position: absolute; height: 30%; text-align: center; width: 100%; margin: auto; top: 0; bottom: 0; right: 0; left: 0; font-size: 30px;.img-responsive sầu display: block; max-width: 100%; height: 120px; margin: auto; padding: auto;.dataNumber margin-top: auto;


.image position: relative; margin-bottom: 20px; width: 100%; height: 300px; color: white; background: url("../../Images/myImg.jpg") no-repeat; background-size: 250px 250px;
Highly active question. Earn 10 reputation in order to answer this question. The reputation requirement helps protect this question from spam and non-answer activity.

Not the answer you're looking for? Browse other questions tagged html css or ask your own question.

site kiến thiết / biệu tượng công ty © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev2021.3.17.38821