【问题标题】:CSS keyframe animations working on one selector but not othersCSS 关键帧动画在一个选择器上工作,但在其他选择器上不工作
【发布时间】:2021-07-02 08:54:54
【问题描述】:

我在我的 CSS 文件中定义了以下简单的关键帧动画,即使第一个工作正常,我也无法让后两个工作:

.hi p {
  font-family: 'Prompt', sans-serif;
  font-size: 20rem;
  color: #f7c089;
  font-weight: bold;
  animation: hiAnimation 1.5s ease-in;
}

@keyframes hiAnimation {
  from {
    opacity: 0;
    margin-left: -2rem;
  }

  to {
    opacity: 1;
    margin-left: 0rem;
  }
}

.intro-name {
  font-family: 'Prompt', sans-serif;
  font-size: 4rem;
  color: #bababa;
  font-weight: 400;
  animation: nameAnimation 1.5s ease-in;
}

@keyframes nameAnimation {
  from {
    opacity: 0;
    margin-top: -2rem;
  }

  to {
    opacity: 1;
    margin-top: 0rem;
  }
}

.intro-title {
  font-family: 'Prompt', sans-serif;
  font-size: 4rem;
  line-height: 70px;
  color: #d6d6d6;
  font-weight: 400;
  animation: titleAnimation 1.5s ease-in;
}

@keyframes titleAnimation {
  from {
    opacity: 0;
    margin-bottom: -2rem;
  }

  to {
    opacity: 1;
    margin-bottom: 0rem;
  }
}

hiAnimation 工作得很好——完全按照预期制作动画——但nameAnimationtitleAnimation 都不起作用,即使它们的格式完全相同。不知道我错过了什么,有什么帮助吗?

【问题讨论】:

    标签: css css-animations keyframe


    【解决方案1】:

    你会减小字体大小:20rem;到 2rem,因为它应该可以工作。 您设置的时间非常短,这就是为什么当您滚动查看已经完成的动画时。 让我知道它对你有用吗。

    【讨论】:

    • 设置为 20rem 的 p 标签工作正常,因此字体大小不是问题所在。所有动画元素在网站的登录页面上都直接相邻,因此不会发生可能导致动画丢失的滚动 - .hi p 标签中的元素会在页面一出现动画就很好加载,但其他即使在它旁边也不会触发。
    猜你喜欢
    • 2015-06-21
    • 2014-07-22
    • 1970-01-01
    • 1970-01-01
    • 2014-05-25
    • 2013-12-12
    • 1970-01-01
    • 1970-01-01
    • 2014-06-29
    相关资源
    最近更新 更多