tags:

views:

11957

answers:

4

Hi, I have a Container with Opacity 0.3

$('#containerFeatured').css('opacity',0.3)

The fact is that when I try to overlay a DIV wrap with images the opacity takes the whole DIV. I tried with z-index but nothing happens.

My example here

Thank you!

+3  A: 

When you specify the opacity of an element (i.e. div), that opacity will apply to its child elements too. An obvious way around this is to get your non-transparent content outside of the div and use CSS positioning.

euge1979
I think this is the best option I think...
cool. mark whatever answer helps you best as 'accepted' so that this question doesn't show up as 'unanswered'. thanks
euge1979
+1  A: 

Other than moving the child elements out and using positioning, You could also use a PNG that is 30% opaque as the background image of the container div, however then you gotta deal with IE6.

benmmc
This is the last option, because y want to preserve the simplicity of the page. Thanks.
Well, really the page would be simpler with this option (the code wouldn't change at all, just adding a background image instead of using the opacity property). That's less complicated than moving child elements out and using positioning.
benmmc
A: 

You could try this:

$(document.createElement('div'))
    .width($('#containerFeatured').width())
    .height($('#containerFeatured').height())
    .css({backgroundColor:'white', opacity:0.4, position:'absolute',left:0, top:0})
    .prependTo($('#containerFeatured'))
$('#containerFeatured').css('position','relative')

You may want to tweak height more, but essentially, will do the trick :)

Ionut Staicu
It doesn't work dude... It looks like a great solution but I don't know what it's wrong, I mean I just know the jQuery Basics. Thanks
Oh, i forgot to mention: you need to remove existing background color and opacity on #containerFeatured :) I'm sure will work because i tested in firebug ;)
Ionut Staicu
A: 

I use an opaque png for the background, then apply Unit Interactives PNG fix

http://labs.unitinteractive.com/unitpngfix.php

I think that's the cleanest, simplest solution.

gargantaun