使用CSS实现中间镂空的图片遮罩效果
2015-12-25 12:08
1061 查看
中间镂空的图片遮罩指的大概就是这样一个效果:
镂空一个洞的代码
镂空多个洞的代码
CSS3 版
用 box-shadow ,代码如下:
缺点是只能镂空一个洞。
镂空一个洞的代码
<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/20141103100737855b7.jpg" /> </div>
镂空多个洞的代码
<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/20141103100737855b7.jpg" /> </div>
CSS3 版
用 box-shadow ,代码如下:
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;
缺点是只能镂空一个洞。
相关文章推荐
- 全局css样式
- I do not want to inherit the child opacity from the parent in CSS(不想让子元素继承父元素的透明度)
- CSS中的几种图片覆盖文本的方法
- css控制Button 按钮的点击时候出现蓝色边框
- css控制Button 按钮的点击时候出现蓝色边框
- CSS的特性
- 【转】CSS3的REM设置字体大小
- 对图片进行各种样式裁对图片进行各种样式裁剪:圆形、星形、心形、花瓣形等剪:圆形、星形、心形、花瓣形等--第三方开源--CustomShapeImageView
- MsgBox图标样式
- js+css中的clip进行的简单的缩略图裁剪
- Css3 过渡(Transition)特效回调函数
- 拒绝IE8-,CSS3 transform rotate旋转动画效果(支持IE9+/chrome/firefox)
- 转:css:Position
- Css之中英文左右(两端)对齐
- CSS样式表——布局练习(制作360网页)
- CSS中display属性知识要点详解
- DotNetBar 第1课,设置整体窗口样式
- HTML&&css练习
- HTML--CSS样式表--格式与布局
- html+css代码需要注意的地方(整理)