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

2022-01-11,,,

这篇文章主要介绍了使用CSS实现中间镂空图片遮罩效果的方法,文中同时附带介绍了一个用CSS3实现的镂空一个圆形的代码示例,需要的朋友可以参考下

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

镂空一个洞的代码
CSS Code复制内容到剪贴板

  1. "container" style="position: relative; margin: 550px 0 0 50px;">   
  2. <svg style="position: absolute;" width="400" height="280">   
  3.   
  4. <mask id="mask3">   
  5. <rect x="0" y="0" width="100%" height="100%" style="stroke:none; fill: #ccc">   
  6. <circle id="circle1" cx="100" cy="100" r="50" style="fill: #000" />   
  7.   
  8.   
  9. <rect x="0" y="0" width="100%" height="100%" style="stroke: none; fill: #ccc; mask: url(#mask3)">   
  10.   
  11. src="http://img6.cache.netease.com/cnews/2014/11/3/20141103100737855b7.jpg-600" />   
  12.   

镂空多个洞的代码

CSS Code复制内容到剪贴板

  1. "container" style="position: relative;">   
  2. <svg style="position: absolute;" width="400" height="280">   
  3.   
  4. <mask id="mask3">   
  5. <rect x="0" y="0" width="100%" height="100%" style="stroke:none; fill: #ccc">   
  6. <circle id="circle1" cx="100" cy="50" r="50" style="fill: #000" />   
  7. <circle id="circle1" cx="300" cy="100" r="50" style="fill: #000" />   
  8. <circle id="circle1" cx="100" cy="200" r="50" style="fill: #000" />   
  9.   
  10.   
  11. <rect x="0" y="0" width="100%" height="100%" style="stroke: none; fill: #ccc; mask: url(#mask3)">   
  12.   
  13. src="http://img6.cache.netease.com/cnews/2014/11/3/20141103100737855b7.jpg-600" />   
  14.   

 

CSS3 版

用 box-shadow ,代码如下:

CSS Code复制内容到剪贴板

  1. positionfixed;   
  2. left150px;   
  3. top35px;   
  4. width100px;   
  5. height100px;   
  6. border-radius: 100px;   
  7. box-shadow: rgba(0,0,0,.8) 0px 0px 0px 2005px;   
  8. z-index: 100;  

缺点是只能镂空一个洞。

 

以上就是使用CSS实现中间镂空的图片遮罩效果的详细内容,更多请关注本站其它相关文章!

《使用CSS实现中间镂空的图片遮罩效果.doc》

下载本文的Word格式文档,以方便收藏与打印。