应用CSS完成正中间镂空的照片遮罩实际效果
日期:2020-12-12 类型:科技新闻 我要分享
关键词:小程序 活动,微信小程序demo,微信小程序游戏开发价格,手机小程序怎么做,视频播放微信小程序
正中间镂空的照片遮罩指的大约便是这样1个实际效果:
镂空1个洞的编码
CSS Code拷贝內容到剪贴板
- <div id="container" style="position: relative; margin: 550px 0 0 50px;">
- <svg style="position: absolute;" width="400" height="280">
- <defs>
- <mask id="mask3">
- <rect x="0" y="0" width="100%" height="100%" style="stroke:none; fill: #ccc"></rect>
- <circle id="circle1" cx="100" cy="100" r="50" style="fill: #000" />
- </mask>
- </defs>
- <rect x="0" y="0" width="100%" height="100%" style="stroke: none; fill: #ccc; mask: url(#mask3)"></rect>
- </svg>
- <img src="http://img6.cache.netease.com/cnews/2014/11/3/207855b7.jpg" />
- </div>
镂空好几个洞的编码
CSS Code拷贝內容到剪贴板
- <div id="container" style="position: relative;">
- <svg style="position: absolute;" width="400" height="280">
- <defs>
- <mask id="mask3">
- <rect x="0" y="0" width="100%" height="100%" style="stroke:none; fill: #ccc"></rect>
- <circle id="circle1" cx="100" cy="50" r="50" style="fill: #000" />
- <circle id="circle1" cx="300" cy="100" r="50" style="fill: #000" />
- <circle id="circle1" cx="100" cy="200" r="50" style="fill: #000" />
- </mask>
- </defs>
- <rect x="0" y="0" width="100%" height="100%" style="stroke: none; fill: #ccc; mask: url(#mask3)"></rect>
- </svg>
- <img src="http://img6.cache.netease.com/cnews/2014/11/3/207855b7.jpg" />
- </div>
CSS3 版
用 box-shadow ,编码以下:
CSS Code拷贝內容到剪贴板
- position: fixed;
- left: 150px;
- top: 35px;
- width: 100px;
- height: 100px;
- border-radius: 100px;
- box-shadow: rgba(0,0,0,.8) 0px 0px 0px 2005px;
- z-index: 100;
缺陷是只能镂空1个洞。