Home > Software engineering >  Animate html text via css
Animate html text via css

Time:11-13

I want to create a text animation, in which the text is automatically and constantly moving from one side to the other side of the website. Like a text would do on a ticker display. Does anybody know about a simple css code I can use to animate the text in this way?

Thanks in advance!

I have tried it out with the tag, but it lags a lot.

CodePudding user response:

Html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="main.css">
    <title>css animation</title>
</head>
<body>
    <h2 >Hello world!</h2>
</body>
</html>

css:

.anim {
    animation: move 2s infinite;
    position: absolute;
    right: 0px;
}

.anim {
    animation: move 5s infinite;
    position: absolute;
  opacity: 1;
}

@keyframes move {
    0%   {left:100%;}
    50%  {left: 0px;}
    100% { opacity:0;}
}

Codepen: https://codepen.io/djalms/pen/GRGmYoZ

CodePudding user response:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />

    <link
      rel="apple-touch-icon"
      type="image/png"
      href="https://cpwebassets.codepen.io/assets/favicon/apple-touch-icon-5ae1a0698dcc2402e9712f7d01ed509a57814f994c660df9f7a952f3060705ee.png"
    />
    <meta name="apple-mobile-web-app-title" content="CodePen" />

    <link
      rel="shortcut icon"
      type="image/x-icon"
      href="https://cpwebassets.codepen.io/assets/favicon/favicon-aec34940fbc1a6e787974dcd360f2c6b63348d4b1f4e06c77743096d55480f33.ico"
    />

    <link
      rel="mask-icon"
      type="image/x-icon"
      href="https://cpwebassets.codepen.io/assets/favicon/logo-pin-8f3771b1072e3c38bd662872f6b673a722f4b3ca2421637d5596661b4e2132cc.svg"
      color="#111"
    />

    <title>CodePen - Wave Text</title>
    <link
      href="https://fonts.googleapis.com/css?family=Righteous&display=swap"
      rel="stylesheet"
    />

    <link
      rel="stylesheet"
      href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css"
    />

    <style>
      .container {
        max-width: 960px;
      }

      body {
        background-color: #fafafa;
      }

      .widthset {
        width: 16.5%;
      }

      .heading-style {
        font-family: "Righteous", cursive;
        font-size: 205px;
        font-weight: bolder;
        -webkit-text-stroke: 2px rgba(6, 188, 209, 0.2);
        background: #ffffff;
        mix-blend-mode: screen;
        padding-top: 190px;
      }

      @media (min-width: 1200px) .container,
        .container-lg,
        .container-md,
        .container-sm,
        .container-xl {
        max-width: 1140px;
      }

      @media (min-width: 992px) .container,
        .container-lg,
        .container-md,
        .container-sm {
        max-width: 960px;
      }

      @media (min-width: 768px) .container, .container-md, .container-sm {
        max-width: 720px;
      }

      @media (min-width: 576px) .container, .container-sm {
        max-width: 540px;
      }

      @media (min-width: 1200px) .container {
        max-width: 1140px;
      }

      @media (min-width: 992px) .container {
        max-width: 960px;
      }

      @media (min-width: 768px) .container {
        max-width: 720px;
      }

      @media (min-width: 576px) .container {
        max-width: 540px;
      }

      .shadow {
        box-shadow: 0px 18px 39.1px 6.9px rgba(224, 241, 255, 0.34) !important;
      }

      .card {
        border: 0;
      }

      .mt-15 {
        margin-top: 15%;
      }

      .progress-wrapper {
        height: 240px;
        overflow: hidden;
      }

      .wave {
        position: absolute;
        width: 100%;
        height: 100%;
      }

      .card-body {
        -ms-flex: 1 1 auto;
        flex: 1 1 auto;
        min-height: 1px;
        padding: 1.25rem;
      }

      .card-title {
        margin-bottom: 0.75rem;
      }

      .list-unstyled {
        padding-left: 0;
        list-style: none;
      }

      .card {
        position: relative;
        display: -ms-flexbox;
        display: flex;
        -ms-flex-direction: column;
        flex-direction: column;
        min-width: 0;
        word-wrap: break-word;
        background-color: #fff;
        background-clip: border-box;
        border: 1px solid rgba(0, 0, 0, 0.125);
        border-radius: 0.25rem;
        margin-bottom: 20px;
      }

      .wave::before,
      .wave::after {
        content: "";
        position: absolute;
        width: 470px;
        height: 390px;
        bottom: 0;
        left: 55%;
        background-color: rgba(255, 255, 255, 0.18);
        border-radius: 70%;
        -webkit-transform: translateX(-50%) rotate(0);
        transform: translateX(-50%) rotate(0);
        -webkit-animation: rotate 6s linear infinite;
        animation: rotate 6s linear infinite;
        z-index: 10;
      }

      .wave::after {
        border-radius: 30%;
        background-color: rgba(255, 255, 255, 0.9);
        -webkit-transform: translateX(-50%) rotate(0);
        transform: translateX(-50%) rotate(0);
        -webkit-animation: rotate 10s linear -5s infinite;
        animation: rotate 10s linear -5s infinite;
        z-index: 20;
      }

      @keyframes rotate {
        50% {
          transform: translateX(-50%) rotate(180deg);
        }

        100% {
          transform: translateX(-50%) rotate(360deg);
        }
      }

      @media only screen and (max-width: 768px) {
        .heading-style {
          font-family: "Righteous", cursive;
          font-size: 156px;
        }

        .progress-wrapper {
          height: 209px;
        }
      }

      @media only screen and (max-width: 425px) {
        .heading-style {
          font-family: "Righteous", cursive;
          font-size: 65px;
        }

        .progress-wrapper {
          height: 148px;
        }

        .wave::before,
        .wave::after {
          width: 490px;
          height: 331px;
        }
      }
    </style>

    <script>
      window.console = window.console || function (t) {};
    </script>

    <script>
      if (document.location.search.match(/type=embed/gi)) {
        window.parent.postMessage("resize", "*");
      }
    </script>
  </head>

  <body translate="no">
    <a href="https://www.youtube.com/watch?v=szLmLFsisbY" target="_blank">
      <section >
        <div >
          <div >
            <div >
              <div
                
                style="
                  background-image: linear-gradient(
                    to bottom,
                    #f8e739,
                    #f1d42d,
                    #eac222,
                    #e1b019,
                    #d89e10
                  );
                "
              >
                <div  style="bottom: 80%">
                  <h1 >H</h1>
                </div>
              </div>
            </div>

            <div >
              <div
                
                style="
                  background-image: linear-gradient(
                    to bottom,
                    #d89e10,
                    #e28f00,
                    #ec7f00,
                    #f66b00,
                    #ff5200
                  );
                "
              >
                <div  style="bottom: 80%">
                  <h1 >E</h1>
                </div>
              </div>
            </div>

            <div >
              <div
                
                style="
                  background-image: linear-gradient(
                    to bottom,
                    #e2130b,
                    #e1110c,
                    #e00f0d,
                    #df0c0d,
                    #de090e
                  );
                "
              >
                <div  style="bottom: 80%">
                  <h1 >L</h1>
                </div>
              </div>
            </div>

            <div >
              <div
                
                style="
                  background-image: linear-gradient(
                    to bottom,
                    #ce0061,
                    #d50079,
                    #d60094,
                    #d000b3,
                    #c115d4
                  );
                "
              >
                <div  style="bottom: 80%">
                  <h1 >L</h1>
                </div>
              </div>
            </div>

            <div >
              <div
                
                style="
                  background-image: linear-gradient(
                    to bottom,
                    #6a0ddc,
                    #5f0ddd,
                    #530edd,
                    #450fde,
                    #3210de
                  );
                "
              >
                <div  style="bottom: 80%">
                  <h1 >O</h1>
                </div>
              </div>
            </div>
          </div>
        </div>
      </section>
    </a>
  </body>
</html>
  • Related