Is the rotate() method in SVG supported on web browsers when passing in additional parameters like angle, centerX, and centerY similar to the CSS rotate

I have recently learned about a rotate transform that allows for rotating around a specified center point using the `rotate(angle, centerX, centerY)` method. However, I have noticed that this method does not seem to work when applied via CSS.

Interestingly, it works perfectly fine when used inline as an attribute:

<svg>
  <circle cx="50" cy="50" r="3" style="fill: black"/>

  <g id="arrow" style="stroke: black">
     <line x1="60" y1="50" x2="90" y2="50"/>
     <polygon points="90, 50, 85 45, 85, 55"/>
  </g>

  <use xlink:href="#arrow" transform="rotate(60, 50, 50)"/>
</svg>

However, applying this through a CSS style rule seems to present issues:

#arrow2 {
  transform: rotate(60, 50, 50);
}
<svg>
  <circle cx="50" cy="50" r="3" style="fill: black"/>

  <g id="arrow" style="stroke: black">
     <line x1="60" y1="50" x2="90" y2="50"/>
     <polygon points="90, 50, 85 45, 85, 55"/>
  </g>

  <g id="arrow2" style="stroke: red">
     <line x1="60" y1="50" x2="90" y2="50"/>
     <polygon points="90, 50, 85 45, 85, 55"/>
  </g>
</svg>

https://i.sstatic.net/ugi6E.png

Answer №1

When it comes to the property "transform," CSS and SVG don't behave the same way. Here's a solution you can try:

#arrow2 {
  transform: rotate(60deg);
  transform-origin: 50px 50px;
}
<svg>
  <circle cx="50" cy="50" r="3" style="fill: black"/>

  <g id="arrow" style="stroke: black">
     <line x1="60" y1="50" x2="90" y2="50"/>
     <polygon points="90, 50, 85 45, 85, 55"/>
  </g>

  <g id="arrow2" style="stroke: red">
     <line x1="60" y1="50" x2="90" y2="50"/>
     <polygon points="90, 50, 85 45, 85, 55"/>
  </g>
</svg>

Answer №2

From what I can gather, CSS transform: rotate() seems to only accept one rotation parameter. More information can be found in the documentation on MDN. It's important to note that the transform-origin property is necessary to adjust the rotation point away from the default center.

It appears that this method works "inside" the SVG due to different parsers used by browsers for SVG and CSS. This likely leads to mapping the overloaded "style" to the native SVG Transform function. The MDN documentation hints at this:

In SVG2, transform is considered a presentation attribute that can also be used as a CSS property. However, there are syntax differences between the CSS property and the attribute. Refer to the documentation for the CSS property transform for specific syntax guidelines.

Keep in mind that the documentation for SVG Transform allows for additional parameters with rotate().

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ensure that the div stays anchored to the bottom of the page while maintaining its

Although I know this question has probably been asked and answered before, I couldn't find any useful solutions to my specific problem... I'm attempting to position a chat box div at the bottom of a page without being fixed, while still maintain ...

CSS not aligning email header correctly

I have been given the task of coding an HTML email for mailing campaigns. I have managed to get everything working, except for a particular piece of code. What I am trying to accomplish is having an image with other elements on top such as titles, a button ...

Developers specializing in Google Maps navigate to a particular destination

I have been working on an app that provides users with the best options for places to visit, utilizing Google Maps technology. Here is what I have accomplished so far: Show the user their current location Show the user possible destinations (with marker ...

Baffling Visibility Issue: iframe's Transparency Lost in Chrome and IE, Only Visible in Firefox

I have encountered a puzzling issue: http://jsfiddle.net/akosk/t2KvE/8/ HTML <div id='base'> <iframe id="myFrame" src="about:blank" frameborder="0" allowTransparency="true"></iframe> </div> <script id="conte ...

Modify the text and purpose of the button

I have a button that I would like to customize. Here is the HTML code for the button: <button class="uk-button uk-position-bottom" onclick="search.start()">Start search</button> The corresponding JavaScript code is as follows: var search = n ...

Rotate the front view image to the left view with a three-dimensional twist

I've been attempting to rotate the image using the code below, but I can only manage to go from a front view to a bottom view. My goal is to rotate the image from the front view to the left view. Is there a way for me to achieve this? body { heig ...

What is the best way to align a dropdown menu and a textbox on the same line

I have recently been working on a search bar that includes a Dropdown for Location and a Textbox for Search. Prior to implementing bootstrap, these elements were displayed in a single line. However, after applying bootstrap, they are now stacked vertically ...

The Bootstrap 4 card component is a versatile and stylish

Currently working on a display layout using Bootstrap 4, specifically utilizing cards. The issue I'm facing is that the text exceeds the limit of the card, causing it to overflow. Is there a solution to make the text automatically wrap to the bottom ...

Leverage predefined JavaScript functions within an Angular template

I have been attempting to execute an eval function within my angular template in the following manner: <div *ngFor="..."> <div *ngIf="eval('...')"></div> </div> You understand what I'm trying to ...

What could be causing my CSS formatting from a linked style sheet to not be applied properly?

I've been trying to incorporate a YouTube video into my webpage using a CSS stylesheet, but I can't seem to get the video to display properly .youtube-video iframe, .youtube-video img, .youtube-video-2 iframe, .youtube-video-2 img { positi ...

What will occur if I use an XMLHttpRequest to request a file that is currently being downloaded?

My goal is to enhance links in a progressive manner using the PJAX style. My plan was to layer this on top of some regular prefetch <link>s: <link rel="prefetch" href="next.html"/> If the browser has already downloaded next.html, then the PJA ...

Transferring Data Between Two Forms

Is there a way to transfer data between two HTML forms? For example, let's say we have two forms: Form 1: Contains a field for name and a submit button. Form 2: Contains fields for name, email, and a submit button. I would like to be able to fill o ...

What is the process for transforming a String into an HTML element within a Next JS Application?

I stored the product description as HTML elements in a Database, but when I try to render this data into a div, it displays as a String. I am looking to showcase all the data as HTML elements in my Next JS application. I attempted using JSON.parse, but unf ...

The code in the head section is not running as expected

I've been exploring the possibilities of using lambda on AWS in combination with api gateway to create a contact form for a static S3 website, all inspired by this informative blog post: https://aws.amazon.com/blogs/architecture/create-dynamic-contact ...

JQuery is failing to locate elements that have dynamic data titles assigned to them

I've been attempting to locate an element using a jQuery regex comparison in the data title. My situation involves having divs with the class .textbox, each containing a dynamically generated data title. To target specific boxes with that particular d ...

Styling the "Browse" button for different web browsers

Here is the code snippet I am working with: HTML: <form> <input id = "file" type="file" /> <div id="custom_button">custom button</div> </form> Jquery: $("#custom_button").on("click", function () { $("#file"). ...

Improving User Experience with HTML Form Currency Field: Automatically Formatting Currency to 2 Decimal Places and Setting Maximum Length

Hello there, I am currently facing an issue with the currency auto-formatting in a deposit field on my form. The formatting adds 2 decimal places (for example, when a user types 2500, the field displays 25.00). However, the script I wrote does not seem to ...

Steps for aligning an image in the center above two divs

I've been attempting to accomplish something without success. The image below should speak a thousand words. My goal is to position div 3, located in div 2, perfectly centered between div 1 and 2 to achieve the desired outcome: Here's my HTML a ...

Navigating HTML with Node.js and Express.js

I have been working on routing multiple HTML pages in my project. The index.html file loads without any issues, but when I try to load raw.html, an error message pops up: Error: Failed to lookup view "error" in views directory Below is part of my app.j ...

What is the best way to use absolute positioning in React Native to align an element with its grandparent?

I am trying to position a Font Awesome icon in a React Native project using absolute positioning relative to the grandparent element, rather than its direct parent. After some research, I came across the following information on this page: https://reactna ...