I have an image which is showed as a background image. I want to set default opacity to 0.5. And wanted some part to be shown without opacity in image. Will it possible purely in css, html, javascript/jQuery?
-
3Possible duplicate of CSS or JavaScript to highlight certain area of image opacityKlinger– Klinger2016-12-21 06:08:32 +00:00Commented Dec 21, 2016 at 6:08
-
@azhar I'm added ananswer if it's helpful don't forget to tick itADH - THE TECHIE GUY– ADH - THE TECHIE GUY2016-12-21 06:20:59 +00:00Commented Dec 21, 2016 at 6:20
Add a comment
|
2 Answers
Here is the trick.
- Create an overlay with
:beforeor:afterpseudo element. - Apply css3 transformation.
- Use large
box-shadowand addoverflow: hiddenon parent to hide undesired part.
.image-holder {
display: inline-block;
position: relative;
vertical-align: top;
overflow: hidden;
}
.image-holder:before {
box-shadow: 0 0 0 1000px rgba(0, 0, 0, 0.5);
transform: skew(-25deg);
-webkit-transform: skew(-25deg);
-webkit-backface-visibility: hidden;
position: absolute;
width: 100px;
bottom: 20px;
content: '';
right: 100px;
top: 20px;
}
.image-holder img {
vertical-align: top;
}
<div class="image-holder">
<img src="http://placehold.it/450x200">
</div>
Comments
you can do this by position an <div> over the image using position:absolute.I'm added an snippet below.
img{
width:300px;
height:300px;
}
#highlight{
position:absolute;
width:100px;
height:100px;
background:#fff;
opacity:0.5;
top:50px;
left:50px;
}
<img src="https://i.sstatic.net/UaQWH.jpg">
<div id="highlight"></div>
