手机
当前位置:查字典教程网 >网页设计 > Div+Css教程 >巧用CSS3 border实现图片遮罩效果代码
巧用CSS3 border实现图片遮罩效果代码
摘要:无标题文档.trans{-webkit-transition:0.3sease;-moz-transition:0.3sease;-ms-t...

<!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="#">

<span></span>

<img src="http://common.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实现图片遮罩效果代码】相关文章:

css实现文字层浮在图片之上示例代码

如何用CSS将图片显示成圆角

纯CSS结合DIV实现的右侧底部简洁悬浮效果

css实现图片在div中居中的效果

利用css实现图片等比例缩放

纯CSS3实现带动画效果导航菜单无需js

CSS实现图片圆角化处理

用css实现透视效果

实现CSS3中的border-radius(边框圆角)示例代码

CSS自动控制图片大小的代码

精品推荐
分类导航