Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keep text opacity 100 when its parent container is having opacity of 50

Tags:

html

css

opacity

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

like image 924
Moksha Avatar asked Jun 22 '11 21:06

Moksha


People also ask

How do I change the opacity of text without affecting it?

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.

Which opacity property value would result in a color that is 100% transparent?

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.

How do you override the opacity of an element as a child?

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.

How do I increase text opacity?

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.


1 Answers

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) } 
  • Browsers that support rgba will use the second background declaration with rgba.
  • Browsers that do not will ignore the second 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/

like image 192
thirtydot Avatar answered Sep 27 '22 18:09

thirtydot