views:

143

answers:

3

I got from web designer layout, which contains (probe):

<div id="subMenuRow">
 <div id="subMenuRowHTML">
  <a href="/link">Link</a>
 </div>
</div>

and respectively css for it:

#subMenuRow{
        width: 900px;
        height: 40px;
        background: #000000;
        float: left;
        clear: both;
        filter:alpha(opacity=30);
        -moz-opacity:0.3;
        -khtml-opacity: 0.3;
        opacity: 0.3;
}

Opacity is used to make transparent bar for html menu. The problem is, that every text including links contains transparency as well, which is very unnecessary. How to avoid opacity for subMenuRowHTML?

A: 

Add:

#subMenuRowHTML {
filter:none;
-moz-opacity:1;
-khtml-opacity:1;
opacity:1;
}

Justin Ryan
This is not going to work, all opacity settings will be relative to the parent's opacity (=never be less transparent than the parent).
Pekka
Ahh, good point.
Justin Ryan
+2  A: 

use a semi transparent .png as a background image:

css:

background: transparent url(/url/image.png) top left repeat;
code-zoop
I think it brings another complications - like transparency for IE6? I have already picture below it...
bluszcz
That is correct! IE6 does not handle transparend png as it should. You could get away with it by using a javascript class to handle this; http://homepage.ntlworld.com/bobosola/
code-zoop
+2  A: 

First you don't need to use -moz-opacity and -khtml-opacity anymore. They are very very old.

There is no solution fully supported today. CSS3 RGBA solves this in modern browsers but if you need to support old browsers you will need to use semi transparent png:

#subMenuRow { background: url(semi-trans.png); }

IE6 will degrade gracefully with this:

* html #subMenuRow { background: url(full-opacity.gif); }

There are also easy options for png transparency on IE6. It's up to you.

If you have many instances of opacity on your code and don't want to mess up your code with * html everywhere you can use conditional comments.

Julio Protzek
Thanks, I will use ie png fix for next projects.
bluszcz