Advertisement


Using Opacity of a Div without affecting The color of the Paragraph inside the Div


Question

I have created a div with background color black, and written a p inside it with white. When I am using opacity in the div, the color of the p is also getting changed into gray. Is there any way to change the opacity only of the div without affecting the color of the p?

2015/06/30
1
0
6/30/2015 5:09:00 PM

Just read this article. It explains everything: https://css-tricks.com/rgba-browser-support/

You should have:

div {
     background: rgba(0, 0, 0, 0.5);
     color: #fff; 
}

There are also same or similar questions here, like this: https://stackoverflow.com/questions/15449280/html-css-text-background-transparent-but-text-not

2017/05/23
2
5/23/2017 12:40:00 PM