Modern CSS offers excellent methods for positioning and moving elements relative to each other, such as anchor positioning. However, there are times when using traditional techniques for simple animations can save time and effort.
Elements have always been adjustable in terms of structure, like resizing and rotating. When an element’s intrinsic sizing changes, its children are also affected, which can be advantageous.
Consider a scenario where circles move towards and across each other, like this:
Our HTML might be a simple `
For rotations, two approaches exist: animating the `
The first option is preferable since animating each `.circle` requires multiple animations instead of one. Before proceeding, ensure each `.circle` is within the `
“`css
main {
contain: layout;
}
.circle {
position: absolute;
&:nth-of-type(1){
background-color: rgb(0, 76, 255);
}
&:nth-of-type(2){
background-color: rgb(255, 60, 0);
right: 0;
}
&:nth-of-type(3){
background-color: rgb(0, 128, 111);
bottom: 0;
}
&:nth-of-type(4){
background-color: rgb(255, 238, 0);
right: 0;
bottom: 0;
}
}
“`
To rotate the `
“`css
/* Applied on
.animate {
width: 0;
transform: rotate(90deg);
transition: width 1s, transform 1.3s;
}
“`
Then apply it to the `
“`javascript
const MAIN = document.querySelector(“main”);
function play() {
MAIN.className = “”;
MAIN.offsetWidth;
MAIN.className = “animate”;
}
“`
It appears as though four circles are animated, but the parent container is rotated and its width changed, affecting the circles.
Each `.circle` is fixed to a corner of the `
This method simplifies crafting and managing animations for simple effects. Additional animations can be layered for variations, like two squares crossing during the animation.
“`css
/* Applied on
.animate {
transform: skewY(30deg) rotateY(180deg);
transition: 1s transform .2s;
.square {
transform: skewY(30deg);
transition: inherit;
}
}
“`
The parent `
For squares to separate without flipping:
“`css
/* Applied on
.animate {
transform: skewY(30deg);
transition: 1s transform .2s;
.square {
transform: skewY(-30deg);
transition: inherit;
}
}
“`
Here, `
Applying `skew()` on a parent rearranges children beyond typical geometry. Changes in the parent can be complemented, countered, or canceled by children, depending on the desired effect.
For scaling:
“`css
/* Applied on
.animate {
transform: rotate(-180deg) scale(.5) skewY(45deg);
transition: .6s .2s;
transition-property: transform, border-radius;
.squares {
transform: skewY(-45deg) scaleX(1.5);
border-radius: 10px;
transition: inherit;
}
}
“`
The `
Discover more from WIREDGORILLA
Subscribe to get the latest posts sent to your email.


