Make SVG shapes transform like Dom elements

For a previous article on this blog I found myself rotating an SVG shape using CSS. At which point I immediately realised that the usual way of shifting the origin of rotation to the centre worked differently for SVG shapes than it did for standard dom elements.

For standard dom elements, you can do the below method, but, by default, it doesn’t work for SVG elements.

.my-class {
    transform-origin: 50% 50%;
    rotate: 45deg;
}

Solution

To support this in SVGs, you need to add one more property to tell it how to calculate the bounding box to which the transformations will relate.

.my-class {
    transform-box: fill-box;
    transform-origin: 50% 50%;
    rotate: 45deg;
}

That’s it!

I found the above solution from this stack overflow thread as presented by user @George. There are also various other older approaches mentioned on that thread if this solution doesn’t work for you.

Thanks…

I also dissect and speculate on design and development.
Digging into subtle details and implications, and exploring broad perspectives and potential paradigm shifts.
Check out my conceptual articles on Substack or find my latest below.


You can also find me on Threads, Bluesky, Mastodon, or X for more diverse posts about ongoing projects.

My latest articles

Keep doing your crappy little drawings (Staging XR scenes)

Some people create beautiful perspective illustrations to visualise and storyboard their virtual reality designs And it’s tempting to think you’re not a strong designer if you’re not doing that too…

Focal point blocking for XR media

Planning out a linear VR experience requires thinking about where the viewers attention might be. Thinking about the focal points…

Designing immersive experiences

In traditional cinema, TV, or even the more modern phone screen, there’s limited screen real-estate. But removing that limitation creates a design problem…

The future is not prompt engineered

Let’s not pretend the importance of prompt engineering is ubiquitous. The most prevalent power of generative AI is in the way it adapts to us, not the other way around…

The typography of dates, times, & filenames

A deep dive into carefully considered date formatting, line length and general typography attributes of filenames…

Loosening the Shackles of Rapid Authoring Tools

Rapid authoring tools like Articulate Storyline and Evolve Authoring make sharing projects possible across a team of non-programmers, but your design must often adapted to the limited range of possibilities the tool allows…
Bluesky
Threads
Twitter / X
Mastodon
Instagram

Author:

Date:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.