I have a div element with text blocks and a parent div in which I have set a background image. Now I want to reduce the opacity of the background image. Please suggest how I can do that.
Thanks in advance.
EDIT:
I am looking to change the way my blog post looks at blogger.com by editing the html content. The html code looks as follows:
<div> //my blog post </div>
I tried to surround the whole code above with a div element and set opacity of each div separately as below:
<div style="background-image:url("image.jpg"); opacity:0.5;"> <div style="opacity:1;"> //my blog post </div> </div>
But it is not working.
Approach: We can use the opacity property in CSS which is used to change the opacity of an element. The value of the property can be set in a range of 0 to 1, where “0” is fully transparent and “1” is opaque. Any decimal value can be used in between to set the opacity accordingly.
There is no background-opacity property in CSS, but you can fake it by inserting a pseudo element with regular opacity the exact size of the element behind it.
opacity is a CSS property that allows you to change the opaqueness of an element. By default, all elements have a value of 1 . By changing this value closer to 0 , the element will appear more and more transparent.
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; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With