Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS Animating SVG with CSS Transitions and Transforms Rotating and Scaling SVG

Piper Nilsson
Piper Nilsson
858 Points

when I applied a transform "scale" to my logo it scaled outside the viewbox (so it looked cropped)

Hello, I tried applying a rotation and scale to a logo element. Here's my code:

leaf {

transition: transform .3s ease-out;
transform-origin: 50% 50%;

}

logo:hover #leaf {

transform: rotate(10deg) scale(1.2);

}

It worked, but when the leaf scales it grows out of the viewbox so it looks cropped. I applied some padding to the svg which seemed to fix it, but I don't really want that extra padding around the logo. Is there a better way to do it?

svg#logo { max-width: 600px; margin: 20px; padding: 5%; }

1 Answer

Bryan Land
Bryan Land
10,306 Points

Use the relative positions of the logo's container element by specifying:

leaf {
  transition: transform .3s ease-out;
  transform-origin: 50% 50%;
  transform-box: fill-box; /* fix for chrome */
}