Reputation: 2670
I am trying to make a image cropping popup where the wrapper has a sphere in it. My target is to make the image transparent to the wrapper except the sphere inside the wrapper.
HTML
<div class="wrapper">
<figure>
<img src="https://iso.500px.com/wp-content/uploads/2016/01/andre_cover.jpg"/>
</figure>
</div>
CSS
.wrapper{
height: 300px;
background-color: red;
position: relative;
}
figure{
width: 200px;
height: 200px;
border-radius: 50%;
margin: 0;
background-color: #fff;
margin: 0 auto;
}
figure img{
opacity: 0.5;
position: absolute;
left: 0;
max-height: 100%;
}
Any help would be appreciated.
Upvotes: 1
Views: 525
Reputation: 19341
Check following which is your expected output.
img {
mask: url(#masking);
}
<svg>
<defs>
<linearGradient id="gradient" x1="0" y1="00%" x2 ="0" y2="100%">
<stop stop-color="black" offset="0"/>
<stop stop-color="white" offset="1"/>
</linearGradient>
<mask id="masking" maskUnits="objectBoundingBox" maskContentUnits="objectBoundingBox">
<rect y="0.3" width="1" height=".7" fill="url(#gradient)" />
<circle cx=".5" cy=".5" r=".35" fill="white" />
</mask>
</defs>
</svg>
<img src="https://iso.500px.com/wp-content/uploads/2016/01/andre_cover.jpg" width="568">
Second Solution:
Using div you can do like following way.
* {
margin: 0;
padding:0;
}
div{
position:relative;
width:450px; height:300px;
overflow:hidden;
left:0;
}
div:after{
content:'';
position:absolute;
left:155px; top:25px;
border-radius:50%;
width:150px; height:150px;
box-shadow: 0px 0px 0px 1000px rgba(255,255,255,0.5);
}
body{background: url('https://iso.500px.com/wp-content/uploads/2016/01/andre_cover.jpg');background-size:450px; background-repeat: no-repeat;}
<div></div>
Edit 2:
If you don't want background then put image inside give.
<div>
<img src="https://iso.500px.com/wp-content/uploads/2016/01/andre_cover.jpg" width="450px" />
</div>
Upvotes: 1
Reputation: 328
You could try to mask it, take a look here: https://webkit.org/blog/181/css-masks/
Upvotes: 0