Change Background Image Opacity


Answer :

Nowadays, it is possible to do it simply with CSS property "background-blend-mode".

<div id="content">Only one div needed</div>  div#content {     background-image: url(my_image.png);     background-color: rgba(255,255,255,0.6);     background-blend-mode: lighten;     /* You may add things like width, height, background-size... */ } 

It will blend the background-color (which is white, 0.6 opacity) into the background image. Learn more here (W3S).


You can't use transparency on background-images directly, but you can achieve this effect with something like this:

http://jsfiddle.net/m4TgL/

HTML:

<div class="container">     <div class="content">//my blog post</div> </div>​ 

CSS:

.container {  position: relative; }  .container:before {     content: "";     position: absolute;     top: 0;     bottom: 0;     left: 0;     right: 0;     z-index: 1;     background-image: url('image.jpg');    opacity: 0.5; }  .content {     position: relative;      z-index: 2; }​ 

There is nothing called background opacity. Opacity is applied to the element, its contents and all its child elements. And this behavior cannot be changed just by overriding the opacity in child elements.

Child vs parent opacity has been a long standing issue and the most common fix for it is using rgba(r,g,b,alpha) background colors. But in this case, since it is a background-image, that solution won't work. One solution would be to generate the image as a PNG with the required opacity in the image itself. Another solution would be to take the child div out and make it absolutely positioned.


Comments

Popular posts from this blog

Are Regular VACUUM ANALYZE Still Recommended Under 9.1?

Can Feynman Diagrams Be Used To Represent Any Perturbation Theory?