Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a child div have a higher opacity than parent with css?

Tags:

css

opacity

I have a background on a page body that is an image which I want to show through the first level of divs but not the second

<body>       <div style='opacity:0.9;'><p>This is a wrapper that shows some of the background</p>           <div style='background-color:#fff;'><p>This is a child div that I want to be all white</p>           </div>       </div> </body> 

Obviously the second level div picks up the opacity of .9 as well is there a way to override this?

like image 995
Brian Avatar asked Apr 04 '12 04:04

Brian


People also ask

Is opacity inherited CSS?

Opacity is not inherited, but because the parent has opacity that applies to everything within it. You cannot make a child element less transparent than the parent, without some trickery. Values are a number from 0 to 1 representing the opacity of the channel (the “alpha” channel).

How do you override opacity in a child element?

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.

Can opacity be more than 1 CSS?

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.

How do you make opacity not affect children?

Answer: Use the CSS RGBA colors There is no CSS property like "background-opacity" that you can use only for changing the opacity or transparency of an element's background without affecting its child elements.


1 Answers

Hi you can do as like this

You can define parent opicity

and child as like you

ex.

css

.parent{     padding:20px;     background:rgba(112,81,246,0.3); } .child{     padding:20px;     background:rgba(112,81,246,0.6); } ​ 

HTML

<div class="parent"> <div class="child">Hello i m child</div> </div>​ 

Live demo here http://jsfiddle.net/rohitazad/PC4sL/

like image 119
Rohit Azad Malik Avatar answered Sep 22 '22 22:09

Rohit Azad Malik