I am trying to overlay a header onto an image. However the background is hidden under the image. Why is this happening?
<div class="header">
<img width="100%" height="200px" src="/path/to/image.jpg" />
<h1>Header Title</h1></div>
h1 {
background: rgba(67,67,67,0.8);
margin-top: -3em;
}
We have 2 solutions here:
Using
display:inline-block
and setwidth:100%
for yourh1
, also use negativemargin-bottom
on theimg
instead:Demo 1.
Using
position:relative
for the img and setz-index:-1
for it:Demo 2.
Are you looking for this Updated Fiddle