Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
582 views
in Technique[技术] by (71.8m points)

background - Is it possible to achieve this level of transparency and saturation with CSS?

I'm trying to achieve the same view I have in Photoshop / Avocode with CSS. But doesn't matter how I overlap the backgrounds and which opacity levels I set - I can't achieve the same level of transparency and saturation.

Is it possible with CSS?

enter image description here

.parent {
height:300px;
width: 650px;
display:flex;
}

.child {
position:relative;
flex:1;
background-image: url(https://images.unsplash.com/photo-1611149956655-0dd788bb763c?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80);
background-position: center;
width:50%;
height:100%;
}
.child::after {
content:'';
position:absolute;
width: 100%;
height: 100%;
/*background-color: rgba(102, 207, 235,.7);*/
background-color: rgba(34,186,226, .7);

}
.child1 {
flex:1;
background-image: url(https://i.imgur.com/t2IIhj1.png);
background-position: center;
width:50%;
height:100%;
}
<div class="parent">
<div class="child"></div>
<div class="child1"></div>
</div>
question from:https://stackoverflow.com/questions/65850609/is-it-possible-to-achieve-this-level-of-transparency-and-saturation-with-css

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Adding a mix-blend-mode can probably help you getting closer:

.parent {
  height: 300px;
  width: 650px;
  display: flex;
}

.child {
  position: relative;
  flex: 1;
  background-image: url(https://images.unsplash.com/photo-1611149956655-0dd788bb763c?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80);
  background-position: center;
  width: 50%;
  height: 100%;
}

.child::after {
  content: '';
  position: absolute;
  width: 100%;
  height: 100%;
  background-color: rgba(34, 186, 226, .7);
    mix-blend-mode: hard-light;
}

.child1 {
  flex: 1;
  background-image: url(https://i.imgur.com/t2IIhj1.png);
  background-position: center;
  width: 50%;
  height: 100%;
}
<div class="parent">
  <div class="child"></div>
  <div class="child1"></div>
</div>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...