Home > Web Front-end > CSS Tutorial > Why Doesn\'t `transform-origin` Work on SVG Groups in Firefox, and How Can I Fix It?

Why Doesn\'t `transform-origin` Work on SVG Groups in Firefox, and How Can I Fix It?

Barbara Streisand
Release: 2024-11-22 21:22:14
Original
800 people have browsed it

Why Doesn't `transform-origin` Work on SVG Groups in Firefox, and How Can I Fix It?

Transform-Origin on SVG Groups: Firefox Specific Solution

In Firefox, setting the transform-origin on an SVG group has been a persistent issue, leaving developers perplexed as to why it seemingly doesn't function. To address this problem, let's delve into a solution that has proven effective.

To illustrate this issue, consider the following SVG code:

<svg>
  <g>
Copy after login

Firefox will ignore the transform-origin property, meaning the group's transformations will not occur around its intended center.

The key to resolving this problem lies in modifying the SVG design. Instead of drawing the shape within the group, it should be created in such a way that its center aligns with the coordinate origin (0, 0). For example:

<svg>
  <rect>
Copy after login

In this scenario, the rectangle's center aligns with the coordinate origin. Subsequently, you can use CSS to create transitions and animations that Firefox will properly execute around the group's center.

For instance, the following CSS snippet would rotate the group (and rectangle) around its center in Firefox:

#myObject {
  transform: rotate(0deg);
  transition: all 1s linear;
}

.csstransforms.csstransitions.js-rotateObject #myObject {
  transform: rotate(360deg);
}
Copy after login

This solution effectively resolves the transform-origin issue in Firefox, allowing for seamless transformations centered around SVG groups.

The above is the detailed content of Why Doesn\'t `transform-origin` Work on SVG Groups in Firefox, and How Can I Fix It?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template