跑马灯代码

<!DOCTYPE html>
<html>
  <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>跑马灯</title>
    <style type="text/css">
      body {
        margin: 0;
        padding: 0;
        background-color: #ccc;
      }
      div {
        margin: 0 auto;
        width: 500px;
        height: 30px;
        line-height: 30px;
        text-align: center;
        border: 1px solid #000;
        border-radius: 10px;
        overflow: hidden;
      }
      p {
        margin: 0;
        background: -webkit-linear-gradient(
          left,
          #ffffff,
          #ff0000 6.25%,
          #ff7d00 12.5%,
          #ffff00 18.75%,
          #00ff00 25%,
          #00ffff 31.25%,
          #0000ff 37.5%,
          #ff00ff 43.75%,
          #ffff00 50%,
          #ff0000 56.25%,
          #ff7d00 62.5%,
          #ffff00 68.75%,
          #00ff00 75%,
          #00ffff 81.25%,
          #0000ff 87.5%,
          #ff00ff 93.75%,
          #ffff00 100%
        );
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        background-size: 200% 100%;
        animation: masked-animation 2s infinite linear;
      }
      @keyframes masked-animation {
        0% {
          background-position: 0 0;
        }
        100% {
          background-position: -100%, 0;
        }
      }
    </style>
  </head>
  <body>
    <div>
      <p>
        天行健,君子以自强不息;地势坤,君子以厚德载物!
      </p>
    </div>
  </body>
</html>

直接复制上面代码,保存为.html文件就可以查看效果了