<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>文字动态背景</title>
<style>
body{
/*取消内外边距*/
margin:0;
padding:0;
/*弹性布局,水平 垂直居中*/
display:flex;
justify-content:center;
align-items:center;
/*100%窗口高度*/
height:100vh;
}
div{
/*文字居中*/
text-align:center;
/*文字大小*/
font-size:120px;
/*文字粗细*/
font-weight:bolder;
/*背景渐变*/
background:linear-gradient(to right,#002fa7,#470024,#fbd26a,#01847f,#492d22,#003153,#d44848,#002fa7);
/*背景大小*/
background-size:400%;
/*背景只在文字中显示*/
background-clip:text;
-webkit-background-clip:text;
/*透明颜色*/
color:transparent;
/*动画 动画运行时间10秒 匀速运行 无限次数*/
animation:text_color 10s linear infinite;
}
/*定义动画*/
@keyframes text_color {
100%{
/*背景位置*/
background-position:-400%;
}
}
</style>
</head>
<body>
<div>
JavaScript
</div>
</body>
</html>