12

I have created a menu block element which I have applied an opacity of 0.4/40 to.

The problem I have is that the opacity affects the text within the menu block and I am looking to have the opacity ONLY applied to the menu block, but not the text.

Hopefully I have just missed something silly. Here is my code:

#menuLeft{
    background-color: #33AAEE;
    float: left;
    width: 20%;
    clear: both;
    opacity:0.4;
    filter: alpha(opacity = 40);
}

I am looking for a way to keep the text colour the same/set the opacity to exclude the text.

Thank you.

Mus
  • 7,290
  • 24
  • 86
  • 130

2 Answers2

21

This is a very, very, very popular problem. Try using rgba():

//Your opacity is the latest value here for Firefox 3+, Safari 3+, Opera 10.10+
background-color: rgba(51, 170, 238, 0.6);
//Your opacity is the first pair here (in HEX!) for IE6+
progid:DXImageTransform.Microsoft.gradient(startColorstr=#9A33AAEE,endColorstr=#9A33AAEE); 
zoom: 1;
float: left;
width: 20%;
clear: both;
/*opacity:0.4;
filter: alpha(opacity = 40);*/

You also can use http://css3please.com/ to easily convert from HEX to RGB and back.

Daniel O'Hara
  • 13,307
  • 3
  • 46
  • 68
  • 1
    Or a very UNpopular problem(!) Thank you so much for your help, it has solved my issue! – Mus Aug 24 '11 at 12:06
0

You could also put a transparent picture as the background. The text should display normally. http://css-tricks.com/snippets/css/transparent-background-images/

sasdev
  • 506
  • 7
  • 23