网页中常常有这样的CSS水波纹的效果,给大家分享一下看效果图看完效果,我们来研究一下是怎么实现呢,给大家用于讲解html+css图片文字排版的基本流程。
1、首先html创建新文件,定义6个div标签。
复制代码1
2
3
4
5
6
<div class="wave wave5"></div>
<div class="wave wave4"></div>
<div class="wave wave3"></div>
<div class="wave wave2"></div>
<div class="wave wave1"></div>
<div class="wave wave0"></div>
登录后复制
2、div盒子的class设置为“.wave
”给它样式设置添加元素绝对定位,语法“position:absolute;left:100px;top:150px
”。
代码示例
复制代码1
2
3
4
5
.wave{
position:absolute;
top:calc((100% - 30px)/2);
left:calc((100% - 30px)/2);
}
登录后复制
3、wave标题文本样式给添加尺寸宽度设置为30px
,高度设置为30px
;给元素添加圆角的边框border-radius
属性。
复制代码1
2
3
4
5
{
width:30px;
height:30px;
border-radius:300p
}
登录后复制
4、wave标题文本样式给插入图片添加background
属性一个div
元素中设置背景图像
复制代码1
background:url(图片地址)
登录后复制
5、wave标题文本样式利用background-attachment
属性设置为 "fixed(固定)
;利用background-position
属性设置背景图像的起始位置。
复制代码1
2
background-attachment:fixed;
background-position:center center
登录后复制
代码效果
6、div盒子的class设置为“wave0-5”给它样式设置设置图像的z-index
属性;再给background-size
属性指定背景图像的大小;动画animation
绑定到一个<div>
元素,只要把六个div
叠在一起,搭配CSS的animation
,就可以让六个div
依序出现。
代码示例
复制代码1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
.wave0{
z-index:2;
background-size:auto 106%;
animation:w 1s forwards;
}
.wave1{
z-index:3;
background-size:auto 102%;
animation:w 1s .2s forwards;
}
.wave2{
z-index:4;
background-size:auto 104%;
animation:w 1s .4s forwards;
}
.wave3{
z-index:5;
background-size:auto 101%;
animation:w 1s .5s forwards;
}
.wave4{
z-index:6;
background-size:auto 102%;
animation:w 1s .8s forwards;
}
.wave5{
z-index:7;
background-size:auto 100%;
animation:w 1s 1s forwards;
}
登录后复制
代码效果
7、通过@keyframes
规则,创建动画是通过逐步改变0%
是开头动画,100%
是当动画完成,注意: 使用animation
属性来控制动画的外观,还使用选择器绑定动画。
复制代码1
2
3
4
5
6
7
8
9
10
11
12
13
@keyframes w{
0%{
top:calc((100% - 30px)/2);
left:calc((100% - 30px)/2);
width:30px;
height:30px;
}
100%{
top:calc((100% - 300px)/2);
left:calc((100% - 300px)/2);
width:300px;
height:300px;
}
登录后复制
代码效果
ok,代码完成
完整代码
复制代码1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
.wave{
position:absolute;
top:calc((100% - 30px)/2);
left:calc((100% - 30px)/2);
width:30px;
height:30px;
border-radius:300px;
background:url(dsd.jpg);
background-attachment:fixed;
background-position:center center;
}
.wave0{
z-index:2;
background-size:auto 106%;
animation:w 1s forwards;
}
.wave1{
z-index:3;
background-size:auto 102%;
animation:w 1s .2s forwards;
}
.wave2{
z-index:4;
background-size:auto 104%;
animation:w 1s .4s forwards;
}
.wave3{
z-index:5;
background-size:auto 101%;
animation:w 1s .5s forwards;
}
.wave4{
z-index:6;
background-size:auto 102%;
animation:w 1s .8s forwards;
}
.wave5{
z-index:7;
background-size:auto 100%;
animation:w 1s 1s forwards;
}
@keyframes w{
0%{
top:calc((100% - 30px)/2);
left:calc((100% - 30px)/2);
width:30px;
height:30px;
}
100%{
top:calc((100% - 300px)/2);
left:calc((100% - 300px)/2);
width:300px;
height:300px;
}
}
</style>
</head>
<body>
<div class="wave wave5"></div>
<div class="wave wave4"></div>
<div class="wave wave3"></div>
<div class="wave wave2"></div>
<div class="wave wave1"></div>
<div class="wave wave0"></div>
</body>
</html>
登录后复制
推荐学习:CSS视频教程
以上就是手把手教你使用CSS制作逼真的水波纹效果(附代码)的详细内容,更多请关注靠谱客其它相关文章!
最后
以上就是优雅钢铁侠最近收集整理的关于手把手教你使用CSS制作逼真的水波纹效果(附代码)的全部内容,更多相关手把手教你使用CSS制作逼真内容请搜索靠谱客的其他文章。
发表评论 取消回复