• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

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

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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

镂空一个洞的代码

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;  

缺点是只能镂空一个洞。

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
CSS毛玻璃效果如何实现发布时间:2022-06-21
下一篇:
小议Data URI scheme及其在CSS中的相关使用发布时间:2022-06-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap