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

bokeyy   发布时间:2015-12-24 12:08:16   作者:袁源   我要评论
这篇文章主要介绍了使用CSS实现中间镂空的图片遮罩效果的方法,文中同时附带介绍了一个用CSS3实现的镂空一个圆形的代码示例,需要的朋友可以参考下

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

20151224120939344.png (383×279)

镂空一个洞的代码

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

镂空多个洞的代码

CSS Code复制内容到剪贴板
  1. <div id="container" style="position: relative;">   
  2. <svg style="position: absolute;" width="400" height="280">   
  3. <defs>   
  4. <mask id="mask3">   
  5. <rect x="0" y="0" width="100%" height="100%" style="stroke:none; fill: #ccc"></rect>   
  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. </mask>   
  10. </defs>   
  11. <rect x="0" y="0" width="100%" height="100%" style="stroke: none; fill: #ccc; mask: url(#mask3)"></rect>   
  12. </svg>   
  13. <img src="http://img6.cache.netease.com/cnews/2014/11/3/20141103100737855b7.jpg" />   
  14. </div>  

 

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实现镂空遮罩效果,本文给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下
    2019-08-20
  • 用纯CSS实现镂空效果的示例代码

    这篇文章主要介绍了用纯CSS实现镂空效果的示例代码的相关资料,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2019-02-25
  • CSS实现镂空效果的示例代码

    这篇文章主要介绍了CSS实现镂空效果的示例代码的相关资料,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2018-12-24
  • CSS3中文字镂空、透明值、阴影效果设置示例小结

    这篇文章主要介绍了CSS中文字镂空、透明值、阴影效果设置示例小结,其中通过text-stroke-color透明值的设置可以让文字在某些程度上更加柔和,需要的朋友可以参考下
    2016-03-07
  • CSS背景色镂空技术实际应用及进阶分享

    这篇文章主要介绍了CSS背景色镂空技术实际应用及进阶相关资料,需要的朋友可以参考下
    2013-10-10
  • css3遮罩层镂空效果的多种实现方法

    这篇文章主要介绍了css3遮罩层镂空效果的多种实现方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学
    2020-05-11

最新评论