演示效果
2022-07-13_17-39-41.png实现思路
先给背景设置了渐变颜色并且旋转一定角度,实现斜着的渐变效果。
接下来把背景放大500%,然后设置了一个15秒的动画,动画infinite无限循环。
动画部分就是对背景进行一个定位,实现渐变颜色的动态切换。
代码
html结构
<!--
* @Descripttion:
* @version:
* @Author: siebe
* @Date: 2022-07-13 17:08:40
* @LastEditors: siebe
* @LastEditTime: 2022-07-13 17:08:40
-->
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Demo</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1>动态渐变背景</h1>
</body>
</html>
css样式
body {
margin: 0;
padding: 0;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background: linear-gradient(135deg, #34ac40, #2c8ae8, #dc47cd, #e7e373);
background-size: 500%;
animation: bgAnimation 6s linear infinite;
}
h1 {
color: white;
letter-spacing: 5px;
}
@keyframes bgAnimation {
0% {
background-position: 0% 50%;
}
50% {
background-position: 100% 50%;
}
100% {
background-position: 0% 50%;
}
}
gitee地址:siebe/html-css-demo (https://gitee.com/siebe/html-css-demo)
网友评论