Yes , instead of using the opacity
property use linear-gradient
. You can "merge" multiple values and fetch the result of background you need.
Using opacity
, 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 background
attribute by separating them with a 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: link