Reputation: 61
I am attempting to make the background color of my div change based on it's containing image. I have seen similar effects on Google, Pinterest et cetera where the color are displayed before the image. Preferably more than one color, maybe as a gradient. Any ideas? Thanks!
Upvotes: 2
Views: 476
Reputation: 14323
This can be accomplished via an image blur.
.container {
position:fixed;
width:200px;
height:150px;
border: 1px solid black;
border-radius: 2px;
overflow:hidden;
}
.background {
width: calc(100% + 40px);
margin-left: -40px;
margin-top: -40px
height:calc(100% + 40px);
position:absolute;
z-index:-1;
filter: blur(40px);
}
.foreground {
border:solid 1px black;
max-width:150px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
<div class="container">
<img class="background" src="https://i.imgur.com/PHEgdUj.jpeg" />
<img class="foreground" src="https://i.imgur.com/PHEgdUj.jpeg" />
</div>
Upvotes: 3