巧用CSS3 border实现图片遮罩效果代码
2012-04-09 22:51
691 查看
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <style type="text/css"> .trans { -webkit-transition: 0.3s ease; -moz-transition: 0.3s ease; -ms-transition: 0.3s ease; -o-transition: 0.3s ease; transition: 0.3s ease; } .test_outer { display: block; width: 200px; height: 200px; margin: 1em auto; position: relative; overflow: hidden; } .test_cover { width: 40px; height: 40px; border: 200px solid rgba(0, 0, 0, .35); border-radius: 50%; position: absolute; left: -115px; top: -165px; } .test_cover:hover { width: 140px; height: 140px; left: -170px; top: -165px; } .test_cover:hover:after { content: "秋思-一叶知秋!"; text-align:center; margin:55px 0 0 12px; color: #fff; font: bold 16px/1.2 '微软雅黑'; text-shadow: 1px 1px rgba(0, 0, 0, .35); position: absolute; } </style> </head> <body> <a href="#" class="test_outer"> <span class="test_cover trans"></span> <img src="http://img.jb51.net/data/avatar/000/00/64/47_avatar_middle.jpg" width="200" height="200" /> </a> </body> </html>
其实现原理是利用个border偌大的半透明边框属性(demo中边框宽度200像素),边框颜色为rgba黑色半透明,然后50%圆角。再用用定位把它覆盖在图片上面。
主要核心代码:
.test_cover { width: 40px; height: 40px; border: 200px solid rgba(0, 0, 0, .35); border-radius: 50%; position: absolute; left: -115px; top: -165px; }
然后外面再用个父容器把它溢出隐藏掉就可以了
.test_outer { display: block; width: 200px; height: 200px; margin: 1em auto; position: relative; overflow: hidden; }
就这么简单....
相关文章推荐
- 巧用CSS3 border制作图片遮罩效果
- CSS3 animation实现图片轮播效果 自动显示 无需使用js 含代码(图片轮播效果一)
- CSS3实用技巧:几行代码实现图片黑白效果
- css3实现图片遮罩效果鼠标hover以后出现文字
- css3实现 鼠标移上图片 放大遮罩效果
- +【CSS3】使用纯css代码实现图片轮播效果
- css3 实现图片遮罩效果,hover出现文字
- +【CSS3】使用纯css代码实现图片轮播效果
- css3实现图片遮罩效果鼠标hover以后出现文字
- 非常惊艳的Css3的桌面上散落的相片效果,以及单击放大图片的LightBox效果(独立Js非jQuery)的实现原理
- 各式各样的导航条效果css3结合jquery代码实现
- CSS3实现鼠标移动到图片上图片变大(缓慢变大,有过渡效果,放大的过程是有动画过渡的,这个过渡的时间可以自定义)
- 图片流动效果实现(代码)
- jQuery实现图片轮播效果代码
- 特殊形状图片之遮罩蒙版CSS3-Mask效果
- Javascript+CSS实现漂亮带缓冲效果的图片展示代码
- Javascript+CSS实现漂亮带缓冲效果的图片展示代码
- 扩展easyui.datagrid,实现加载数据遮罩效果代码
- CSS3实现DIV圆角效果完整代码
- 用JS实现图片轮播效果代码(一)