-2

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?

Below is the sample image. enter image description here

2

2 Answers 2

3

Here is the trick.

  1. Create an overlay with :before or :after pseudo element.
  2. Apply css3 transformation.
  3. Use large box-shadow and add overflow: hidden on 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>

Sign up to request clarification or add additional context in comments.

Comments

0

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>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.