简体   繁体   English

如何使图像围绕圆圈透明

[英]How to make the image transparent around the circle

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 HTML

<div class="wrapper">
  <figure>
    <img src="https://iso.500px.com/wp-content/uploads/2016/01/andre_cover.jpg"/>
  </figure>
</div>

CSS 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%;
}

Demo 演示

Any help would be appreciated. 任何帮助,将不胜感激。

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"> 

Reference link 参考链接

Second Solution: 第二种解决方案:

Using div you can do like following way. 使用div,您可以按照以下方式进行操作。

 * { 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> 

Fiddle link 小提琴链接

Edit 2: 编辑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>

New Fiddle 新提琴

您可以尝试掩盖它,在这里看看: https : //webkit.org/blog/181/css-masks/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM