1. 定义背景缩放动画
@keyframes bg-move {
0% {
background-position: 0 50%;
}
50% {
background-position: 100% 50%;
}
0% {
background-position: 0 50%;
}
}
2. 定义容器渐变背景并应用动画
.container {
width: 100%;
height: 100%;
background-image: linear-gradient(to right,
#eea2a2 0%, #bbc1bf 19%, #57c6e1 42%, #b49fda 79%, #7ac5d8 100%
);
background-size: 400%;
animation: bg-move 20s infinite;
}
3. 完整代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
html, body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
.container {
width: 100%;
height: 100%;
background-image: linear-gradient(to right,
#eea2a2 0%, #bbc1bf 19%, #57c6e1 42%, #b49fda 79%, #7ac5d8 100%
);
background-size: 400%;
animation: bg-move 20s infinite;
}
@keyframes bg-move {
0% {
background-position: 0 50%;
}
50% {
background-position: 100% 50%;
}
0% {
background-position: 0 50%;
}
}
</style>
</head>
<body>
<div class="container"></div>
</body>
</html>
4. 更多渐变效果参考
https://color.oulu.me/