【发布时间】:2021-06-08 17:06:39
【问题描述】:
我正在尝试创建一个由两部分组成的重复背景。每个部分都是一个渐变,一个向上移动,另一个向下移动。
我得到的最好的是:
html {
background: black;
color: #4c4c4c;
}
body {
margin: 30vh auto;
max-width: 80vw;
}
.wave {
background: none;
height: 1rem;
width: 50%;
position: absolute;
z-index: 2;
animation: move 700ms 0ms steps(2) infinite both;
}
.color::after,
.color::before {
content: "";
position: absolute;
left: 0;
right: 0;
height: 100%;
top: 0;
}
.color {
background-image: linear-gradient(#fe0000 50%, #6531ff 0 100%);
}
.color::after {
background: linear-gradient(to bottom, #f4e04d, #3bceac 20%, rgba(22, 22, 22, 0) 100%), linear-gradient(to right, #042a2b 3rem, transparent 3rem, transparent 6rem);
}
.wave,
.color::after,
.color::before {
background-size: 5rem 1rem;
background-repeat: repeat-x;
}
@keyframes move {
0% {
margin-top: -3rem;
}
100% {
margin-top: -3.25rem;
}
}
<div class="color wave"></div>
我明白为什么这不起作用,但不知道如何继续。
首先(位置 1),所有奇数块都高于偶数块。在第一个动画之后,它是相反的(位置 2)等等。
【问题讨论】:
标签: css css-animations background-image linear-gradients