Thursday, January 3, 2019

html - How do I give text or an image a transparent background using CSS?



Is it possible, using CSS only, to make the background of an element semi-transparent but have the content (text & images) of the element opaque?



I'd like to accomplish this without having the text and the background as two separate elements.



When trying:






p {
position: absolute;
background-color: green;
filter: alpha(opacity=60);
opacity: 0.6;
}

span {
color: white;
filter: alpha(opacity=100);

opacity: 1;
}


Hello world






It looks like child elements are subjected to the opacity of their parents, so opacity:1 is relative to the opacity:0.6 of the parent.



Answer



Either use a semi-transparent PNG image or use CSS 3:



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


Here's an article from css3.info, Opacity, RGBA and compromise (2007-06-03).










Hello, World!





No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...