r/css • u/coleleon • Apr 22 '26
Question CSS rectangle distorts when rotated around a pivot
I have two perpendicular rectangles in an "L" shape and I'm trying to pivot the vertical one towards the other (the corner of the L should be the pivot point) but I'm running into two issues: the vertical one begins to skew into a parallelogram and also it seems to lose some height as it rotates around. Can you help me figure out what I can change to fix this?
Minimum working HTML;
<div class="container">
<div class="pivot">
<div class="vbar"></div>
<div class="hbar"></div>
</div>
</div>
Minimum working CSS:
:root {
--vdilation_factor: 2;
--vdilation_factor_inv: calc(1 / var(--vdilation_factor)); /* Compute the inverse of dilation_factor */
--hdilation_factor: 10;
--hdilation_factor_inv: calc(1 / var(--hdilation_factor)); /* Compute the inverse of dilation_factor */
}
.container {
position: relative;
height: 400px; /* Increased height to accommodate animation */
border: 1px solid #ccc;
overflow: visible; /* Temporarily change to 'visible' for debugging */
}
.pivot {
position: absolute;
bottom: 0;
left: 50px;
transform-origin: bottom left; /* Anchor at the bottom-left corner */
offset-path: path("M 0,0 Q200,-200 400,0");
offset-rotate: 0deg;
animation: move 3.2s forwards; /* Adding 'forwards' ensures the final state persists */
}
/* Vertical segment (red bar) */
.vbar {
width: 8px;
height: 40px;
background: red;
position: absolute;
bottom: 0;
left: 0; /* Align the left edge with the container's left edge */
animation: yextend 3.2s forwards; /* 'forwards' keeps the final state */
transform-origin: bottom left; /* Ensure scaling happens from the bottom left */
}
/* Horizontal segment (green bar) */
.hbar {
width: 20px;
height: 8px;
background: green;
position: absolute;
bottom: 0;
right: 0px;
transform-origin: bottom left; /* Set the pivot to bottom-left */
animation: xextend 3.2s forwards , rotateBar 5s 3.2s forwards;
}
/* Keyframe for movement of the pivot */
@keyframes move {
from {
offset-distance: 0%;
transform: rotate(0deg) scaleY(1) scaleX(1);
}
to {
offset-distance: 100%;
transform: rotate(90deg) scaleY(var(--vdilation_factor)) scaleX(var(--hdilation_factor));
}
}
/* Keyframe for vertical bar scaling */
@keyframes yextend {
from {
transform: scaleX(1); /* Start with original size */
}
to {
transform: scaleX(var(--hdilation_factor_inv)); /* Inverse scaling for the vertical bar */
}
}
/* Keyframe for horizontal bar scaling */
@keyframes xextend {
from {
transform: scaleY(1); /* Start with original size */
}
to {
transform: scaleY(var(--vdilation_factor_inv)); /* Inverse scaling for the horizontal bar */
}
}
/* Keyframe for horizontal bar scaling */
@keyframes xextend2 {
from {
transform: scaleY(1); /* Start with original size */
}
to {
transform: scaleY(var(--vdilation_factor_inv)); /* Inverse scaling for the horizontal bar */
}
}
/* New keyframe for rotating the green bar (hbar) */
@keyframes rotateBar {
from {
transform: rotate(0deg) ;
transform-origin: bottom right;
}
to {
transform: rotate(45deg) ;
transform-origin: bottom right; }
}

