Reputation: 435
I would like to display the background-color of the text in the picture without changing the position. How can I do that?
<div id="pic" ><img src="c.jpg" width="200" height="200"></div>
<p id="text"> ABC</p>
<style>
#text {
background-color:#ff0000;
margin-top: -50px;
position: static;
}
</style>
Upvotes: 0
Views: 47
Reputation: 106
Just change from static to relative.
<style>
#text {
background-color:#ff0000;
margin-top: -50px;
position: relative;
}
</style>
And if you want to be doubly sure, z-index: 1;
Upvotes: 0
Reputation: 2753
This is actually an ordering issue, the picture is above the background color, the text is above the picture.
See this answer for ways this was accomplished: (CSS) How position text (with background color) over <img> tag without absolute positioning
Upvotes: 2