Reputation: 5
How do I create a style rule that sets the font color to white in older browsers, and to white with 50% opacity in newer browsers?
Upvotes: 0
Views: 20
Reputation: 66093
Just use a stacked rule. Put the declaration that is most widely supported first, due to the cascading nature of CSS. Older browsers that cannot interpret rgba
will ignore the line. Newer browsers that can, on the other hand, will accept both, but since the rgba
declaration comes last, it will be the one that takes precedence.
p {
color: #fff;
color: rgba(255,255,255,0.5);
}
ps: Of course <p>
is just a generic element that I've used. You can use any selector.
Upvotes: 2