CSS绘制简易水滴

从B站看到一个有趣的教程,现在把实现它的代码放在这里。将下面的代码直接复制粘贴入一个.html文件保存并打开,即可得到一个简单的动态水滴💧。你可以自行修改动画中将要展现的border-radius效果,阴影范围,高光(即下文#water::before和#water::after两个)的形状和大小,以及动画播放的速度。

HTML

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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>water</title>
<style>
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
body{
width: 100vw;
height: 100vh;
display: flex;
justify-content: center;
background-color: #00a8ff;
}
#water{
margin-top: 200px;
width: 300px;
height: 300px;
/*border: 1px solid #000000;*/
border-radius: 23% 77% 55% 45% / 19% 51% 49% 81% ;
box-shadow: inset 10px 20px 30px rgba(0,0,0,0.5),
10px 10px 20px rgba(0,0,0,0.3),
15px 15px 30px rgba(0,0,0,0.05),
inset -10px -10px 15px rgba(225,225,225,0.8);
animation: action 5s linear infinite alternate;
}
#water::after{
content: '';
width: 20px;
height: 20px;
position: absolute;
top: 240px;
left: 48%;
background-color: rgba(225,225,225,0.8);
border-radius: 50% 50% 63% 37% / 54% 63% 37% 46% ;
animation: action 5s linear infinite alternate;
}
#water::before{
content: '';
width: 10px;
height: 10px;
position: absolute;
top: 265px;
left: 47%;
background-color: rgba(225,225,225,0.8);
border-radius: 42% 58% 63% 37% / 63% 71% 29% 37% ;
animation: action 5s linear infinite alternate;
}
@keyframes action{
25%{
border-radius: 72% 28% 55% 45% / 52% 31% 69% 48% ;
}
50%{
border-radius: 32% 68% 36% 64% / 37% 58% 42% 63% ;
}
100%{
border-radius: 64% 36% 80% 20% / 66% 39% 61% 34% ;
}
}
</style>
</head>
<body>
<dev id="water"></dev>
</body>
</html>

点击查看示例。

  • Copyrights © 2025 Kaleid Scoper
  • 访问人数: | 浏览次数:

欢迎打赏支持作者

支付宝
微信