【问题标题】:Making a CSS Loop Typing Effect Responsive使 CSS 循环键入效果具有响应性
【发布时间】:2021-06-29 16:33:36
【问题描述】:

我使用 HTML 和 CSS 创建了打字机效果。它在网络上运行良好,但在移动设备上它不适合屏幕的宽度。如何使效果响应?我希望背景图像保持静止。这是我的代码:

.typewriter h1 {
  overflow: hidden;
  border-right: .15em solid orange;
  white-space: nowrap;
  margin: 0 auto;
  letter-spacing: .3em;
  font-weight: bold;
  animation: typing 5s steps(40, end), blink-caret .75s step-end infinite;
  animation-iteration-count: infinite;
}

@keyframes typing {
  from {
    width: 0
  }
  to {
    width: 15em
  }
}

@keyframes blink-caret {
  from,
  to {
    border-color: transparent
  }
  50% {
    border-color: orange;
  }
}
<div class="container">
  <div class="typewriter">
    <h1>Model Running . . .</h1>
  </div>
</div>

桌面

手机

【问题讨论】:

    标签: html css animation responsive caret


    【解决方案1】:

    我用@media减少了移动版上的font-size。这意味着,如果屏幕不超过 800 像素,则减少 font-size。如果这不是您想要的,请告诉我。

    代码如下:

    .typewriter h1 {
      overflow: hidden;
      border-right: .15em solid orange;
      white-space: nowrap;
      margin: 0 auto;
      letter-spacing: .3em;
      font-weight: bold;
      animation: typing 5s steps(40, end), blink-caret .75s step-end infinite;
      animation-iteration-count: infinite;
    }
    
    @keyframes typing {
      from {
        width: 0
      }
      to {
        width: 15em
      }
    }
    
    @keyframes blink-caret {
      from,
      to {
        border-color: transparent
      }
      50% {
        border-color: orange;
      }
    }
    
    @media screen and (max-width: 800px){
        .typewriter h1 {
        overflow: hidden;
        border-right: .15em solid orange;
        white-space: nowrap;
        margin: 0 auto;
        letter-spacing: .3em;
        font-weight: bold;
        animation: typing 5s steps(40, end), blink-caret .75s step-end infinite;
        animation-iteration-count: infinite;
        font-size: 20px;
      }
    
      @keyframes typing {
        from {
          width: 0
        }
        to {
          width: 15em
        }
      }
    
      @keyframes blink-caret {
        from,
        to {
          border-color: transparent
        }
        50% {
          border-color: orange;
        }
      }
    }
    <div class="container">
      <div class="typewriter">
        <h1>Model Running . . .</h1>
      </div>
    </div>

    【讨论】:

      【解决方案2】:

      对于图像 I,您可以添加最大宽度 (100%/100vw) 但是对于文本我认为你必须使用CSS Media Queries 来设置不同的大小。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-06-09
        • 1970-01-01
        • 1970-01-01
        • 2016-12-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多