Jump to content

Problems with opacity


ChaosKnight

Recommended Posts

I'm busy with an "ultra-modern" type of look on a project, so I tried something I have seen before, the background is a carbon-looking striped background that is somewhat dark, and for the content I placed a black box with curved edges, and on top of that I have another div that is supposed to contain the content, but I want to make that a bit lighter, so I made that div's background color white, after I have done that I decided it would look awesome if the black div at the back had some opacity, so I set it to 0.3, but then I discovered that the white div also received the opacity of the parent div, so I tried setting it's opacity to 1.0, but it still didn't work, now the content div looks a bit greyish...

 

Here is my CSS code:

#body {
position: relative;
top: 10px;
background: black;
filter: alpha(opacity=30);
-moz-opacity: 0.3;
-khtml-opacity: 0.3;
opacity: 0.3;
-webkit-border-radius: 10px;
        -moz-border-radius: 10px;
-khtml-border-radius: 10px;
border-radius: 10px;
width: 960px;
height: 450px;
margin-left: auto;
margin-right: auto;
}
#content {
position: relative;
filter: alpha(opacity=100);
-moz-opacity: 1.0;
-khtml-opacity: 1.0;
opacity: 1.0;
-webkit-border-radius: 10px;
        -moz-border-radius: 10px;
-khtml-border-radius: 10px;
border-radius: 10px;
top: 10px;
left: 10px;
height: 430px;
width: 940px;
background: white;
}

 

And here is the HTML part:

<div id="body">
<div id="content">

</div>
</div>

 

Can someone please tell me how to get the content div completely white again without any opacity?

 

Thanks!

Link to comment
Share on other sites

The maximum opacity of an element is the opacity of it's parent. So if you drop the parent down to 50%, the maximum opacity of the children (i.e. 100%) is only 50%.

 

There are two ways around this:

1) Use a trasparent .png image as your background. With this method, you don't need to set any opacity.

2) Remove the child from the parent, the use either relative or absolute positioning to position the child (which isn't a child anymore) overtop the parent (which isn't a parent anymore).

 

Method 1: easier, more reliable, but requires an extra HTTP request.

Method 2: Won't work for may situations, can be buggy across browsers, and generally a pain in the butt.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.