如何使用CSS如何实现中间镂空的图片遮罩效果

刚坐在车里就开始电闪雷鸣。听着隆隆的雷声,没有恐慌,到有几分振奋人心的舒心感、酣畅淋漓感。朝外望去,突然间,狂风夹杂着骤雨席卷而来,一泻千里。瞬间暴雨如注,打在地上,溅起朵朵浪花,在热浪的蒸腾下激起层层水雾。满大街是慌乱的人群,行人跑着、叫喊着,唧唧喳喳的赶着在房檐下躲雨。这时候伞是没有用的,挡不住狂风暴雨的袭击,无论是带了伞的,还是没带伞的,全都躲在了房檐下。

中间镂空的图片遮罩指的大概就是这样一个效果:

镂空一个洞的代码

CSS Code复制内容到剪贴板
  1. <divid="container"style="position:relative;margin:550px0050px;">
  2. <svgstyle="position:absolute;"width="400"height="280">
  3. <defs>
  4. <maskid="mask3">
  5. <rectx="0"y="0"width="100%"height="100%"style="stroke:none;fill:#ccc"></rect>
  6. <circleid="circle1"cx="100"cy="100"r="50"style="fill:#000"/>
  7. </mask>
  8. </defs>
  9. <rectx="0"y="0"width="100%"height="100%"style="stroke:none;fill:#ccc;mask:url(#mask3)"></rect>
  10. </svg>
  11. <imgsrc="http://img6.cache.netease.com/cnews/2014/11/3/20141103100737855b7.jpg"/>
  12. </div>

镂空多个洞的代码

CSS Code复制内容到剪贴板
  1. <divid="container"style="position:relative;">
  2. <svgstyle="position:absolute;"width="400"height="280">
  3. <defs>
  4. <maskid="mask3">
  5. <rectx="0"y="0"width="100%"height="100%"style="stroke:none;fill:#ccc"></rect>
  6. <circleid="circle1"cx="100"cy="50"r="50"style="fill:#000"/>
  7. <circleid="circle1"cx="300"cy="100"r="50"style="fill:#000"/>
  8. <circleid="circle1"cx="100"cy="200"r="50"style="fill:#000"/>
  9. </mask>
  10. </defs>
  11. <rectx="0"y="0"width="100%"height="100%"style="stroke:none;fill:#ccc;mask:url(#mask3)"></rect>
  12. </svg>
  13. <imgsrc="http://img6.cache.netease.com/cnews/2014/11/3/20141103100737855b7.jpg"/>
  14. </div>

CSS3 版

用 box-shadow ,代码如下:

CSS Code复制内容到剪贴板
  1. position:fixed;
  2. left:150px;
  3. top:35px;
  4. width:100px;
  5. height:100px;
  6. border-radius:100px;
  7. box-shadow:rgba(0,0,0,.8)0px0px0px2005px;
  8. z-index:100;

缺点是只能镂空一个洞。

到此这篇关于如何使用CSS如何实现中间镂空的图片遮罩效果就介绍到这了。无论你有多少朋友,不能少了书这个诤友。更多相关如何使用CSS如何实现中间镂空的图片遮罩效果内容请查看相关栏目,小编编辑不易,再次感谢大家的支持!

标签: