I have a list div which have a opacity set to 50 and inside this div I want to display some text with opacity 100,
Here's what I mean:
<div id="outer"> <div id="inner"> Text </div> </div>
The CSS would be:
#outer { opacity: 0.5; } #inner { opacity: 1.0; }
I tried that, but it doesn't work.
please help
Regards
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.
The opacity of the channel (the alpha channel) is represented by a value ranging from 0 to 1. The lower the opacity property value, the more transparent an element appears. So, a value of 0 makes an element not opaque at all or fully transparent, whereas a value of 1 makes an element appear totally opaque.
Basically, you can't override the opacity of a child. The answer you might be looking for will depend on what it is you are actually trying to do. Paulie is right, opacity effects the entire element (including children) and can't be reversed by a child element.
Text Opacity CSS You can set the opacity of an entire element — the background, text within the element, the border, and everything else — using the opacity property. To set the opacity of text and only text, then you need to use the CSS color property and RGBA color values.
A simple and compatible solution is to remove all your opacity
, and use:
#outer { background: url(50%-transparent-white.png); background: rgba(255,255,255,0.5) }
rgba
will use the second background
declaration with rgba
.background
declaration and use the .png
.The .png
won't work in IE6, but that's unlikely to be a problem. If it is, it can be resolved.
Yet another method is detailed here:
http://robertnyman.com/2010/01/11/css-background-transparency-without-affecting-child-elements-through-rgba-and-filters/
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