css动画从绝对变为相对

css动画从绝对变为相对,css,animation,css-animations,Css,Animation,Css Animations,我已经找到了这个wave动画“”,并希望在我的页面上的标题上使用它,但问题是,动画是为绝对值编写的,但我需要一个相对位置,因为动画应该位于页面顶部 我曾尝试将“位置类型”更改为“相对”,但无论如何我都会破坏动画,如果有人能帮助我,我会很高兴^^ 谢谢大家抽出时间 以下是css: html, body { height: 100%; } body { background:radial-gradient(ellipse at center, rgba(255,254,234,1) 0%, rg

我已经找到了这个wave动画“”,并希望在我的页面上的标题上使用它,但问题是,动画是为绝对值编写的,但我需要一个相对位置,因为动画应该位于页面顶部

我曾尝试将“位置类型”更改为“相对”,但无论如何我都会破坏动画,如果有人能帮助我,我会很高兴^^

谢谢大家抽出时间

以下是css:

html, body { height: 100%; }
body {
  background:radial-gradient(ellipse at center, rgba(255,254,234,1) 0%, rgba(255,254,234,1) 35%, rgba(254,208,149,1) 100%);
  overflow: hidden;
}

.ocean { 
  height: 5%;
  width:100%;
  position:absolute;
  bottom:0;
  left:0;
  background: #015871;
}

.wave {
  background: url(http://tedmcdo.com/labs/wave.svg) repeat-x; 
  position: absolute;
  top: -198px;
  width: 6400px;
  height: 198px;
  animation: wave 7s cubic-bezier( 0.36, 0.45, 0.63, 0.53) infinite;
  transform: translate3d(0, 0, 0);
}

.wave:nth-of-type(2) {
  top: -175px;
  animation: wave 7s cubic-bezier( 0.36, 0.45, 0.63, 0.53) -.125s infinite, swell 7s ease -1.25s infinite;
  opacity: 1;
}

@keyframes wave {
  0% {
    margin-left: 0;
  }
  100% {
    margin-left: -1600px;
  }
}

@keyframes swell {
  0%, 100% {
    transform: translate3d(0,-25px,0);
  }
  50% {
    transform: translate3d(0,5px,0);
  }
}
把它放在一个相对的div(或其他容器)中,相对容器中的海洋将是绝对的。那可能会解决你的问题

<div style="position: relative">
   <div class="ocean" style="position: absolute"></div>
</div>

将其放入相对div(或其他容器)中,相对容器中的海洋将是绝对的。那可能会解决你的问题

<div style="position: relative">
   <div class="ocean" style="position: absolute"></div>
</div>

不太清楚您的意思:

...need a relative position since the animation should stay on top of the page.
……但我离题了

添加包含相对定位的div

<div class="oceanContainer">
    <div class="ocean">
        <div class="wave"></div>
        <div class="wave"></div>
    </div>
</div>
不过,您可能需要调整一些其他CSS

.ocean {
  height: 5%; /* as above, adjust to %, px, (r)em's to your liking */
  bottom: 0;
}

.wave {
  bottom: 0;    /* change top to bottom */
}

.wave:nth-of-type(2) {
  bottom: 0;    /* change top to bottom */
}

我不太清楚你的意思:

...need a relative position since the animation should stay on top of the page.
……但我离题了

添加包含相对定位的div

<div class="oceanContainer">
    <div class="ocean">
        <div class="wave"></div>
        <div class="wave"></div>
    </div>
</div>
不过,您可能需要调整一些其他CSS

.ocean {
  height: 5%; /* as above, adjust to %, px, (r)em's to your liking */
  bottom: 0;
}

.wave {
  bottom: 0;    /* change top to bottom */
}

.wave:nth-of-type(2) {
  bottom: 0;    /* change top to bottom */
}

大家好,欢迎来到Stack Overflow,请花点时间浏览“了解您在这里的道路”(也可以赢取您的第一个徽章),阅读如何创建并检查,以增加获得反馈和有用答案的机会。大家好,欢迎来到Stack Overflow,请花点时间浏览“了解您在这里的道路”(也是为了赢得你的第一枚徽章),阅读如何创建和检查,以增加获得反馈和有用答案的机会。谢谢你们的帮助,我可以完成wave。祝你们有一天愉快。谢谢你们的帮助,我可以完成wave。祝你们有一天愉快。