Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Playing with CSS Opacity

Tags:

css

opacity

I am trying to create a buttonbar using simple <div> and change its opacity to 50% and give a background

But the elements which come inside this division exhibit the same transparency as there parent <div>. I want them to retain 100% opacity. (Which is not possible). How to make this Possible?

A sample CSS of what I am trying to do is this

<style>    
    #bar { background:#09f;opacity:0.5; }
    #bar a { background:#FF0;opacity:1; }
</style>
<div id="bar">
    <a href="#">Home</a>
    <a href="#">Contact</a>
    <a href="#">Feedback</a> 
</div>
like image 619
Starx Avatar asked May 11 '26 01:05

Starx


2 Answers

You need to use the rgba property for that, since opacity affects all children.

#bar { background: rgba(0, 120, 255, 0.5); }

Chris Coyier (CSS-tricks) has written a post about this: http://css-tricks.com/rgba-browser-support/

like image 193
peirix Avatar answered May 13 '26 14:05

peirix


if you want only the background to be opaque, you could use a transparent png or an rgba-value as background. otherwise this isn't possible (as you mentioned).

like image 32
oezi Avatar answered May 13 '26 15:05

oezi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!