开发者

CSS - Apply Opacity to Element but NOT To Text Within The Element

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;
    o开发者_Go百科pacity: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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜