Yes, instead of using the property opacity
utilize linear-gradient
. You can "merge" various values and search for the result of background who is in need.
Using opacity
, the child elements will also be affected. For example:
div {
background: url(http://static-files.cdnandroid.com/1f/48/ef/32/imagen-paisagem-hd-live-wallpaper-2-0thumb.jpg) repeat;
box-sizing: border-box;
width: 100%;
height: 300px;
opacity: 0.2; /* usando opacidade */
}
<div>
<img src='http://static-files.cdnandroid.com/1f/48/ef/32/imagen-paisagem-hd-live-wallpaper-2-0thumb.jpg' alt='minha imagem' />
</div>
Now the same example using linear-gradient
:
div {
background:
/*aplicando linear gradient*/
linear-gradient(to bottom, rgba(255, 255, 255, 0.7) 0%, rgba(255, 255, 255, 0.7) 100%),
/* e a imagem de background */
url(http://static-files.cdnandroid.com/1f/48/ef/32/imagen-paisagem-hd-live-wallpaper-2-0thumb.jpg);
box-sizing: border-box;
width: 100%;
height: 300px;
}
<div>
<img src='http://static-files.cdnandroid.com/1f/48/ef/32/imagen-paisagem-hd-live-wallpaper-2-0thumb.jpg' alt='minha imagem' />
</div>
You can merge multiple values into the attribute background
separating them by comma, for example:
background: linear-gradient(to top, rgba(255,255,255,0.5) 0%, rgba(255,255,255,0.5) 100%),
url("url_da_imagem");
--
Reference: https://developer.mozilla.org/en-US/docs/CSS/Multiple_backgrounds
You want to use an image as a transparency mask?
– Oralista de Sistemas
No, I want to use a background image applying opacity by CSS directly. But I’m not sure that’s possible.
– dsantoro
You want a div that goes over other elements, that this div has a background image, and that this background is semi-transparent via CSS. Got it right now?
– Oralista de Sistemas
No rs. Follow link ai. http://drop.studiogt.com.br/g8/index.php/receitas-internal
– dsantoro
This image that comes from the side and is over this div with a background image. I need bg to be opaque.
– dsantoro
post an image simulating the desired effect, otherwise it is difficult to understand. What is the problem with opacity in your specific case? You can’t just apply it to the desired div?
– Bacco
I think you want to make one lightbox. Would that be?
– bfavaretto
In the example you showed, it is a div behind with the image in its normal size and an upper div with the image in a smaller size. To apply the opacity effect you already.
– Renan Gomes
Is your doubt about opacity and not about overlay? Apply opacity to background element only?
– Papa Charlie