代码
提交代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <!-- 在这里用link标签引入中文渐变色 --> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/chinese-gradient"> <style> /* 清除默认样式 */ * { padding: 0; margin: 0; } /* 令html和body全屏显示 */ html, body { height: 100% } /* 上面的那栏 */ .top { /* 设置为固定定位 */ position: fixed; /* 距离上边左边为0 */ top: 0; left: 0; /* 宽度铺满屏幕 */ width: 100%; /* 给个合适的高度 */ height: 80px; /* 蓝色背景 */ background: var(--靛蓝); /* 运行动画 */ animation: hide 2s ease-in infinite alternate } .main { /* 给个合适的上边距 */ margin-top: 90px; /* 给个合适的高度 */ height: 100%; /* 渐变背景 */ background: var(--天蓝); /* 运行动画 */ animation: move 2s ease-in infinite alternate } /* 让盒子里的文字变成白色 */ div { color: white } @keyframes move { to { margin-top: 0 } } @keyframes hide { from { opacity: .7 } to { opacity: .5 } } </style> </head> <body> <div class="top" style="font-size: 30px;">无论你怎么滑动屏幕,我都是固定不变的</div> <div class="main" style="font-size: 30px;"> 这里是主盒子 </div> </body> </html>
运行结果