user2013488
user2013488

Reputation: 363

Transparent div with text on image

I want to accomplish the following effect. (link)

The idea is that I want a transparent div on the top of the image and in this div i want to place a text with opacity: 1 (non-transparent)

So far I managed to make the div transparent, but all the text in it is also transparent and I don't want that.

Upvotes: 1

Views: 95

Answers (2)

jagmitg
jagmitg

Reputation: 4546

This should help you out.

HTML:

<div class="image">
    <img src="images/anyimg.jpg" alt="" />
    <h2>Image text:<br />Image Text</h2>
</div>

CSS:

.image {
    position: relative;
    margin-bottom: 20px;
    width: 100%;
}
h2 {
    position: absolute;
    top: 200px;
    left: 0;
    width: 100%;
}
h2 span {
    color: white;
    font: bold 24px/45px Helvetica, Sans-Serif;
    letter-spacing: -1px;
    background: rgb(0, 0, 0);
    background: rgba(0, 0, 0, 0.7);
    padding: 10px;
}
h2 span.spacer {
    padding: 0 2px;
    background: none;
}

Upvotes: 2

user1370510
user1370510

Reputation: 120

.image
{
  position: absolute;
  top:200px;
  left:200px;
  z-index: -1;
  height:200px;
  width:200px;
  opacity:.5;

}
.text
{
  position: absolute;
  top:50px;
  left:50px;
  z-index: 1000;
  opacity:1;
}
<div>
<img src="image.jpg" class="imgage" />
<span class="text">Hello</span>
</div>

Upvotes: 0

Related Questions