Home > Web Front-end > CSS Tutorial > Why Doesn\'t `transform-origin` Work Correctly on SVG Groups in Firefox?

Why Doesn\'t `transform-origin` Work Correctly on SVG Groups in Firefox?

Susan Sarandon
Release: 2024-12-02 06:24:10
Original
538 people have browsed it

Why Doesn't `transform-origin` Work Correctly on SVG Groups in Firefox?

Resolving transform-origin Issues in SVG Group for Firefox

Problem Statement

Setting transform-origin on an SVG group doesn't seem to have any effect in Firefox. While this works as intended in Webkit browsers, the transform-origin doesn't align properly when used in Firefox.

Code Example

#test {
  -webkit-transform-origin: 50% 50%;
  transform-origin: center center;
 ...
}
Copy after login

Solution

To address this issue, it is recommended to draw the original SVG shape with its center at coordinate (0, 0). This involves shifting the origin of the shape to align correctly with the expected transform-origin.

Revised SVG

<svg x="0px" y="0px" width="400px" height="400px" viewBox="0 0 400 400">
    <g transform="translate(150, 100)">
        <rect>
Copy after login

By placing the center of the shape at (0, 0), the transform-origin can now be correctly applied, resulting in the desired transformation behavior within Firefox.

The above is the detailed content of Why Doesn\'t `transform-origin` Work Correctly on SVG Groups in Firefox?. 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