I have the following HTML code which simply shows an image with a transparent black overlay containing text.
I don't wan't my text to be transparent. I tried with z-index
, but my text is still transparent:
What's wrong with my code?
This is my HTML:
<div class="leftContainer">
<div class = "promo">
<img src="images/soon.png" width="415" height="200" alt="soon event" />
<div class="hilight">
<h2>Hockey</h2>
<p>Sample text</p>
</div>
</div>
...
</div>
and this is my css:
.hilight h2{
font-family: Helvetica, Verdana;
color: #FFF;
z-index: 200;
}
.promo {
position: relative;
}
.promo img {
z-index: 1;
}
.hilight {
background-color: #000;
position: absolute;
height: 85px;
width: 415px;
opacity: 0.65;
font-family: Verdana, Geneva, sans-serif;
color: #FFF;
bottom: 0px;
z-index: 1;
}
The percentage of opacity is calculated as Opacity% = Opacity * 100 To set the opacity only to the background and not the text inside it. It can be set by using the RGBA color values instead of the opacity property because using the opacity property can make the text inside it fully transparent element.
For having a simple, transparent text on an image, you need to have your image or background image in a <div> element, and the content block in another <div>. Then, use the CSS opacity property to set a transparent image or text. The opacity property is used to adjust the transparency of a text or photo.
filter: alpha(opacity=90); opacity: . 9; to make the DIV transparent, but when I add another DIV inside this DIV it makes it transparent also.
To set the opacity of a background, image, text, or other element, you can use the CSS opacity property. Values for this property range from 0 to 1. If you set the property to 0, the styled element will be completely transparent (ie. invisible).
change the background of .hilight to rgba(0,0,0,0.65) and remove the opacity.
.hilight {
background-color: rgba(0,0,0,0.65);
position: absolute;
height: 85px;
width: 415px;
font-family: Verdana, Geneva, sans-serif;
color: #FFF;
bottom: 0px;
z-index: 1;
}
You need to set the opacity to the background only, not the entire div and it's contents. You can do this with rgba
color selection eg
div {
background: rgba(0,0,0,0.50);
}
The other way of doing it would be to use a semi-transparent png
image with some background-position
. This would then be multibrowser compatible
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With