I'm trying to grey out a section of an image (two stripes at left and right). Is there a way to do this using just CSS?
I know I can use filters (i.e. filter: grayscale(100%)
), but I don't want the entire image to be grey.
Pure CSS Solution with no extra markup
JSFIDDLE DEMO
HTML
<div class="image-container">
<img class="image-grey" src="http://placekitten.com/200/150" />
</div>
CSS
.image-container {
position:relative;
display:inline-block;
}
.image-grey {
display:block;
-webkit-filter: grayscale(100%);
}
.image-container:after {
position:absolute;
content:"";
top:0;
left:50%;
width:50%;
height:100%;
background-image:url(http://placekitten.com/200/150);
background-position:top right;
}
Put a div over it.
<div id="wrapper">
<img src="path/to/file.jpg" />
<div id="filter">
</div>
<style>
#wrapper {position: relative;}
#filter {
position: absolute;
top: 123px;
left: 123px;
width: 42px;
height: 42px;
background: rgba(255,0,0,0.5);
}
</style>
http://jsfiddle.net/BQ7J3/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With