The initial positioning seems to be altered when the animation property is included. when the transform origin property is removed or added it will yield the same effect. The initial transforms are getting overridden by the animation.
div {
border-radius: 45px;
}
body {
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
section[id ^='sec'] {
border-radius: 45px;
}
.container {
position: relative;
width: 10em;
height: 10em;
background: red;
}
#sec1 {
right: 0;
position: absolute;
height: 40%;
width: 40%;
background: yellow;
transform: translateX(100px) translateY(-80px)
}
#sec2 {
height: 40%;
width: 40%;
background: aqua;
transform: translateX(-100px) translateY(-80px)
}
#sec3 {
position: absolute;
bottom: 0;
left: 0;
height: 40%;
width: 40%;
background: green;
transform: translateX(-100px) translateY(80px)
}
#sec4 {
position: absolute;
height: 40%;
width: 40%;
right: 0;
bottom: 0;
background: purple;
transform: translateX(100px) translateY(80px)
}
#sec5 {
position: absolute;
bottom: 50;
left: 0;
height: 40%;
width: 40%;
background: navajowhite;
transform: translateX(-100px) translateY(-10px)
}
#sec6 {
position: absolute;
bottom: 50;
right: 0;
height: 40%;
width: 40%;
background: teal;
transform: translateX(100px) translateY(-10px)
}
#sec7 {
position: absolute;
bottom: 0;
right: 0;
height: 40%;
width: 40%;
background: pink;
transform: translateX(-50px) translateY(100px);
}
#sec8 {
position: absolute;
top: 0;
left: 0;
height: 40%;
width: 40%;
background: cadetblue;
transform: translateX(50px) translateY(-100px);
animation: float 6s ease-in-out infinite;
}
@keyframes float {
0% {
transform-origin: initial;
transform: translateY(-100px);
}
50% {
transform-origin: initial;
transform: translateY(-120px);
}
100% {
transform-origin: initial;
transform: translateY(-100px);
}
}
<div class="container">
<section id="sec1"></section>
<section id="sec2"></section>
<section id="sec3"></section>
<section id="sec4"></section>
<section id="sec5"></section>
<section id="sec6"></section>
<section id="sec7"></section>
<section id="sec8"></section>
</div>