Mobile app version of vmapp.org
Login or Join
Jamie315

: Using Opacity of a Div without affecting The color of the Paragraph inside the Div I have created a div with background color black, and written a p inside it with white. When I am using

@Jamie315

Posted in: #Css #Html

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?

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Jamie315

2 Comments

Sorted by latest first Latest Oldest Best

 

@Samaraweera207

You can use css :after selector to give shadow dom element the background color and opacity. This will not effect to p tag.
Here is jsfiddle jsfiddle.net/vjandrei/fyvc3ejy/2/

10% popularity Vote Up Vote Down


 

@Merenda852

Just read this article. It explains everything: 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: stackoverflow.com/questions/15449280/html-css-text-background-transparent-but-text-not

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme