更新第38个小实例

This commit is contained in:
DESKTOP-BM6RJU5\wyanh 2021-11-10 17:19:29 +08:00
parent f2cb8a9ef4
commit 00425b7353
3 changed files with 190 additions and 1 deletions

View File

@ -41,4 +41,5 @@
34. HTML5+CSS3小实例之超酷的字体发光效果
35. HTML5+CSS3小实例之超酷的文字滚动特效
36. HTML5+CSS3小实例之伸缩式动态搜索框
37. HTML5+CSS3小实例之JS+CSS实现日月交替效果
37. HTML5+CSS3小实例之JS+CSS实现日月交替效果
38. HTML5+CSS3小实例之3D分层按钮的悬停效果

120
css/38.css Normal file
View File

@ -0,0 +1,120 @@
*{
/* 初始化 取消内外边距 */
margin: 0;
padding: 0;
/* 设置的边框和内边距的值是包含在总宽高内的 */
box-sizing: border-box;
}
body{
/* 100%窗口高度 */
height: 100vh;
/* 弹性布局 水平垂直居中 */
display: flex;
justify-content: center;
align-items: center;
/* 渐变背景 */
background: linear-gradient(200deg,#29323c,#485563);
}
.icon-box{
/* 弹性布局 水平排列 */
display: flex;
flex-direction: row;
}
.icon-box a{
color: #fff;
margin: 0 30px;
text-decoration: none;
display: block;
/* 相对定位 */
position: relative;
}
.icon-box a .layer{
width: 70px;
height: 70px;
/* 动画过渡 */
transition: 0.3s;
}
.icon-box a .layer i{
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
/* 通过var函数调用自定义属性--c */
border: 1px solid var(--c);
border-radius: 6px;
transition: 0.3s;
}
.icon-box a .layer i.fa{
font-size: 35px;
text-align: center;
line-height: 70px;
color: var(--c);
}
.icon-box a .text{
/* 绝对定位 */
position: absolute;
bottom: 0;
opacity: 0;
width: 100%;
text-align: center;
color: var(--c);
/* 动画过渡 */
transition: 0.3s;
}
.icon-box a:hover .text{
/* 鼠标移入文本出现 */
bottom: -35px;
opacity: 1;
}
.icon-box a:hover .layer{
/* 鼠标移入,该元素旋转-35度并倾斜20度 */
transform: rotate(-35deg) skew(20deg);
}
/* 鼠标移入,设置图标外的每一层边框的样式(不透明度+位置偏移) */
.icon-box a:hover .layer i:nth-child(1){
opacity: 0.2;
transform: translate(0,0);
}
.icon-box a:hover .layer i:nth-child(2){
opacity: 0.4;
transform: translate(5px,-5px);
}
.icon-box a:hover .layer i:nth-child(3){
opacity: 0.6;
transform: translate(10px,-10px);
}
.icon-box a:hover .layer i:nth-child(4){
opacity: 0.8;
transform: translate(15px,-15px);
}
.icon-box a:hover .layer i:nth-child(5){
opacity: 1;
transform: translate(20px,-20px);
}
/* 鼠标移入,设置每一层边框的阴影样式 */
.icon-box a:hover .layer i{
box-shadow: -1px 1px 3px var(--c);
}
/* 接下来为每一个按钮设置不同颜色 */
.icon-box a:nth-child(1) .layer i,
.icon-box a:nth-child(1) .text{
/* --c是自定义属性这里为颜色值可通过var函数进行调用 */
--c: #12b7f5;
}
.icon-box a:nth-child(2) .layer i,
.icon-box a:nth-child(2) .text{
--c: #2aae67;
}
.icon-box a:nth-child(3) .layer i,
.icon-box a:nth-child(3) .text{
--c: #e79115;
}
.icon-box a:nth-child(4) .layer i,
.icon-box a:nth-child(4) .text{
--c: #2075fd;
}
.icon-box a:nth-child(5) .layer i,
.icon-box a:nth-child(5) .text{
--c: #2d8dc5;
}

68
html/38.html Normal file
View File

@ -0,0 +1,68 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
<title>3D分层按钮的悬停效果</title>
<link href="https://cdn.bootcdn.net/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<link rel="stylesheet" href="../css/38.css">
</head>
<body>
<div class="icon-box">
<a href="#">
<div class="layer">
<i></i>
<i></i>
<i></i>
<i></i>
<i class="fa fa-qq" aria-hidden="true"></i>
</div>
<div class="text">QQ</div>
</a>
<a href="#">
<div class="layer">
<i></i>
<i></i>
<i></i>
<i></i>
<i class="fa fa-weixin" aria-hidden="true"></i>
</div>
<div class="text">微信</div>
</a>
<a href="#">
<div class="layer">
<i></i>
<i></i>
<i></i>
<i></i>
<i class="fa fa-weibo" aria-hidden="true"></i>
</div>
<div class="text">微博</div>
</a>
<a href="#">
<div class="layer">
<i></i>
<i></i>
<i></i>
<i></i>
<i class="fa fa-renren" aria-hidden="true"></i>
</div>
<div class="text">人人网</div>
</a>
<a href="#">
<div class="layer">
<i></i>
<i></i>
<i></i>
<i></i>
<i class="fa fa-twitter" aria-hidden="true"></i>
</div>
<div class="text">推特</div>
</a>
</div>
</body>
</html>