CSS - Opaque text on low opacity div?

Dan picture Dan · Mar 8, 2010 · Viewed 33.4k times · Source

I have a div with 60% opacity, to show part of a background image behind the div. Because the opacity is at 60%, the text in that div appears as grey.

Is there anyway to override this level and make the text appear black?

Any advice appreciated.

Thanks.

Answer

Quentin picture Quentin · Mar 8, 2010

Set the opacity on the background rather than the element.

background-color: rgba(255,0,0,0.6);

A while ago I wrote about how to achieve this in a backwards compatible way.