With CSS is it possible to merge two Images?

Asked

Viewed 674 times

2

I saw this and wondered if it would be possible to merge two images with CSS only.

inserir a descrição da imagem aqui




Is there any way to control this partial transparency of one image over the other, or of an image over a background or text?

inserir a descrição da imagem aqui

I tried with opacity, but it did not even come close to the desired effect, as it does not have the "merging" of an image merging in the other.

body {
  margin: 0;
  padding: 0;
}
main {
  position: relative;
}
.bg1,
.bg2 {
  position: absolute;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-size: cover;
  background-repeat: none;
  background-position: center;
}

.bg1 {
  background-image: url(https://unsplash.it/600x400/?image=881);
}

.bg2 {
  background-image: url(https://unsplash.it/600x400/?image=902);
  opacity: .5;
}
<main>
  <div class="bg1"></div>
  <div class="bg2"></div>
</main>

2 answers

1


img {
  -webkit-mask-image: linear-gradient(to bottom, transparent 0%, black 100%);
}
<img src="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png" />

Use Mask-image CSS, see below.

Example where the image has opacity gradient from right to left (to left).

The opacity parameter can be changed here rgba(0, 0, 0, 1), where 1 is the visible maximum.

Apply in the sense you need in other images (to left, to right, to bottom, ...)

img  {
   -webkit-mask-image: linear-gradient(to left, rgba(0,0,0,1), rgba(0,0,0,0)));
}
  • 1

    Welcome Tiago, I’ll give you a hint. Edit your answer and use this btn http://prntscr.com/lui4hw to create a practical example. It will be much better for the community to see and understand your answer!

  • Thanks for the tip, the code has been changed :)

-1

you can use the RGBA in your backgroud (Image), and set the transparency at the end, for example

attribute { background-color : rgba(50,50,100, 0.5) - where 0.5 would be the amount of transparency applied.

  • Friend this I already have, only I used opacity. I want the imagem has 100% color on one side and 0% on the other.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.