巧用CSS3 border完成照片遮罩实际效果编码

日期:2020-10-25 类型:科技新闻 

关键词:在线网页制作,建网页,个人简介网页制作,简单网页,建立网页


拷贝编码
编码以下:

<!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⑻" />
<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: ⑴15px;
top: ⑴65px;
}
.test_cover:hover {
width: 140px;
height: 140px;
left: ⑴70px;
top: ⑴65px;
}
.test_cover:hover:after {
content: "秋思-1叶知秋!";
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: ⑴15px;
top: ⑴65px;
}

随后外面再用个父器皿把它外溢掩藏掉便可以了

拷贝编码
编码以下:

.test_outer {
display: block;
width: 200px;
height: 200px;
margin: 1em auto;
position: relative;
overflow: hidden;
}

就这么简易....