-2

I want to place text over the image like the following picture shows :

enter image description here

HTML that I wrote is :

<body>
<div class="image_holder">
    <img src="bg2.jpg" /> 
    <div class="overlay"> </div>
</div>

<div>NHS SUB</div>   
</body>

CSS :

    .image_holder {
    position:relative;
    float:left;
}

.overlay {
    position:absolute;
    top:0;
    background-color:rgba(34,70,118,0.7);
    width:100%;
    height:100%;
}

The text will automatically go after the image. What should I do to place the text over the image ?

Suhail Gupta
  • 22,386
  • 64
  • 200
  • 328

2 Answers2

0

Try this

<div class="image_holder">
    <div class="overlay">NHS SUB</div>
</div>

Style

.image_holder{
  background:url('img.jpg');
}

Another Way

<div class="image_holder">
    <img src="img.jpg"/>
    <div class="overlay">NHS SUB</div>
</div>

STYLE

.img_holder{
   position:relative;
}
.img_holder img{
   postion:absolute;
   z-index:-1;
}
.overlay{
   z-index:1;
}
Benjamin
  • 2,612
  • 2
  • 20
  • 32
0

Your div class's look like they should infact be ID's. ID's are unique where as class's are used across numerous elements.

Although your nested div approach will work when applying the correct styles, a more semantic (and less markup) would be using Ben's approach - code:

    <div class="mydiv" style="background-image:url('bg2.jpg');">overlay text here</div>
    <div>NHS SUB</div>   
Bruford
  • 471
  • 1
  • 3
  • 13