Created
March 30, 2022 12:44
-
-
Save jens1101/f4c0d3dbd23c1ddeef4a0640acb5c1c7 to your computer and use it in GitHub Desktop.
Scaling an SVG shape from the center of the shape
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<svg viewbox="0 0 300 300"> | |
<rect id="my-rect" x="50" y="50" width="100" height="80" /> | |
</svg>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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