Skip to content

Instantly share code, notes, and snippets.

@jens1101
Created March 30, 2022 12:44
Show Gist options
  • Save jens1101/f4c0d3dbd23c1ddeef4a0640acb5c1c7 to your computer and use it in GitHub Desktop.
Save jens1101/f4c0d3dbd23c1ddeef4a0640acb5c1c7 to your computer and use it in GitHub Desktop.
Scaling an SVG shape from the center of the shape
<svg viewbox="0 0 300 300">
<rect id="my-rect" x="50" y="50" width="100" height="80" />
</svg>;
#my-rect {
transform: scale(1);
transform-box: fill-box; // <- This is the magical property that makes it work
transform-origin: center;
animation: scaleBox 1s infinite alternate ease-in-out;
}
@keyframes scaleBox {
to {
transform: scale(2);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment