Вы можете создать свой фон по-разному, используя repeating-linear-gradient
, а затем анимировать background-size
, как показано ниже:
div.box {
background-image:
repeating-linear-gradient(to bottom,transparent,transparent 98px,lightGray 98px,lightGray 100px),
repeating-linear-gradient(to right, transparent,transparent 98px,lightGray 98px,lightGray 100px),
repeating-linear-gradient(to bottom,transparent ,transparent 19px,rgba(255, 255, 255, 0.3) 19px,rgba(255, 255, 255, 0.3) 20px),
repeating-linear-gradient(to right, transparent ,transparent 19px,rgba(255, 255, 255, 0.3) 19px,rgba(255, 255, 255, 0.3) 20px);
background-repeat:no-repeat;
background-color: #269;
width: 300px;
height: 300px;
animation:gridWipe 3s linear;
}
@keyframes gridWipe {
0% {
background-size:0 0;
}
100% {
background-size:100% 100%;
}
}
p {
background: rgba(255,255,0,0.5);
}
<div class="box">
<p>Lorem ipsum</p>
</div>
Вы также можете рассмотреть некоторые переменные CSS для оптимизации вашего кода:
div.box {
--l_b:2px; /*width of the big line*/
--l_s:1px; /*width of the small line*/
--d_b:100px; /*distance between big lines*/
--d_s:20px; /*distance between small lines*/
--c1:transparent,transparent calc(var(--d_b) - var(--l_b)),lightGray calc(var(--d_b) - var(--l_b)),lightGray var(--d_b);
--c2:transparent,transparent calc(var(--d_s) - var(--l_s)),rgba(255, 255, 255, 0.3) calc(var(--d_s) - var(--l_s)),rgba(255, 255, 255, 0.3) var(--d_s);
background-image:
repeating-linear-gradient(to bottom,var(--c1)),
repeating-linear-gradient(to right, var(--c1)),
repeating-linear-gradient(to bottom,var(--c2)),
repeating-linear-gradient(to right, var(--c2));
background-repeat:no-repeat;
background-color: #269;
width: 300px;
height: 300px;
animation:gridWipe 3s linear;
}
@keyframes gridWipe {
0% {
background-size:0 0;
}
100% {
background-size:100% 100%;
}
}
p {
background: rgba(255,255,0,0.5);
}
<div class="box">
<p>Lorem ipsum</p>
</div>