My intention is to make a parent square which contain four smaller child cubes. I would want an animation to have those four smaller cubes move around within the parent cube. I first make one cube and move it around like so:
.parent {
background-color: aliceblue;
height: 400px;
width: 400px;
margin: 25px;
padding: 25px;
}
.child{
background: black;
position: absolute;
height:100px;
width:100px;
animation: move_around 5s ease-in-out infinite backwards;
}
@keyframes move_around {
0% {
transform: translateX(0%);
}
25% {
transform:translateY(300%);
}
50% {
transform:translateY(300%) translateX(300%);
}
75% {
transform: translateX(300%);
}
}
<div class="parent">
<div class='child'></div>
</div>
However, my intention is to make four of those little cubes, and I want them to start at each corner. Of course I could manually add another cube by adding another child and adding a new custom animation to it, like so:
.parent {
background-color: aliceblue;
height: 400px;
width: 400px;
margin: 100px;
padding: 25px;
}
.child{
background: black;
position: absolute;
height:100px;
width:100px;
}
.top {
animation: move_around 5s ease-in-out infinite backwards
}
.bot {
animation: move_around_bot 5s ease-in-out infinite backwards
}
@keyframes move_around {
0% {
transform: translateX(0%);
}
25% {
transform:translateY(300%);
}
50% {
transform:translateY(300%) translateX(300%);
}
75% {
transform: translateX(300%);
}
}
@keyframes move_around_bot {
0% {
transform:translateY(300%) translateX(300%);
}
25% {
transform: translateY(0%) translateX(300%);
}
50% {
transform: translateY(0%) translateX(0%)
}
75% {
transform: translateX(0%) translateY(300%);
}
100% {
transform:translateY(300%) translateX(300%);
}
}
<div class="parent">
<div class='child top'></div>
<div class='child bot'></div>
</div>
However, this does not seem like the best way. Now I have two, with more then double the amount of lines. Would it need double again the amount of lines for four cubes? What if I want even more cubes? My approach does not seem very usable in this way.
I realized that the second cube here is identical to the first cube, except that its animation is basically 50% of the frames 'ahead'. Is there a way to add a 3rd, 4th or Nth cube that are 25%, 75% or X% of the frames 'ahead'?