I'm looking for a solution to this issue for an hour and what I found on internet never match exactly what I'm looking for. I want to center a text on a image with CSS. The height of the image is defined automatically in regard of the width of the div (which is a percentage).
Here the html code:
<div>
<img src="image.jpg" id="image"/>
<span id="texte"> Texte </span>
</div>
Here the CSS code (which doesn't work):
#div
{
position: relative;
margin: 0px;
padding: 0px;
width:45%;
text-align:center;
}
#texte
{
display: block;
padding: 0px;
margin-left:auto;
margin-right:auto;
z-index: 2;
}
#image
{
width:100%;
height:auto;
display: block;
padding: 0px;
z-index: 1;
}
Thanks for your help.
Green textblue text span>green text
. Your text needs the p tag. Also, div is not an id on its own. You need to specify – CHoltzman Aug 31 '15 at 04:37