Implementing a CSS3 rotation around the center of a group following prior local rotations around the center of each individual item

My dilemma lies within a div containing numerous draggable items. When I select and group multiple items, rotating them together as a group works seamlessly – that is, unless the individual items had prior rotations applied to them.

The issue arises when individual items possess local rotations from before, resulting in deviations in position and functionality of the group rotation.

I believe the root of the problem stems from the differing transform-origin values used for individual rotations compared to group rotations. While item rotations use 50% 50% as the center point, rotating a group necessitates a new origin at the center of the group.

For example, if item1 initially had a local rotation of 45 degrees and was then grouped with other items and collectively rotated by 30 degrees, item1 should have a total rotation of 45 degrees relative to itself and 30 degrees in relation to the center of the group.

CSS3 only allows for one transform-origin, making it challenging to combine different transformations on an item with distinct origins. Despite my attempts with matrices, the results are unsatisfactory when dealing with items that already have rotations. Everything functions perfectly if there are no prior rotations on the items, allowing the group to rotate smoothly around its center. However, things fall apart when items contain individual rotations.

Therefore, my question pertains to how we can integrate two rotations (or any transformations) on the same item with varying transform-origins, such as a local rotation and a group rotation.

Answer №1

To mimic multiple transform-origins, you can apply a translate() function before and after the transformation. Check out this example for more clarity: (might have a slow loading time)

Remember that each transform function alters the entire coordinate system, making it easier to comprehend the changes being made.

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

Adding a custom stylesheet to a particular table within an HTML document

Is it possible to apply an external CSS stylesheet to only one table out of several on the same page? ...

Strikethrough feature not specified on the website

Check out this unique website that showcases text with a strikethrough. Interestingly, I couldn't find any mention of it in the CSS or HTML code. Here is a snippet from the code: <div style="width:100%;height:259px;background-image: url('< ...

How to customize the color of radio buttons in JFXRadioButton using CSS

I am facing an issue with customizing the styling of JFXRadioButton component from this library : jfoenix.com I want to modify the color of the circle, but the default class is not working. Are there any suggestions or solutions available? (The colors me ...

Position a grid item in the center

Can someone help me with centering my container's item? I am struggling to align the third item to the center using display: grid. Previously, I attempted to use flexbox but found it to be less effective for a responsive layout. .projetos { f ...

What is the best way to change the background color of a specific link in the top navigation bar in WordPress?

I'm currently facing a challenge while attempting to create a single link within a WordPress top navigation menu that has a unique background color. Although my approach seems to work on most pages, I've encountered issues where it doesn't ...

Customize the yellow background color of Safari's autofill feature by following these simple

When I open this image in Safari, this is what I see: https://i.stack.imgur.com/KbyGP.png However, this is the code I have: https://i.stack.imgur.com/4wEf0.png References: How to Remove WebKit's Banana-Yellow Autofill Background Remove forced ye ...

How to align scrolling images with their scroll origin - a step by step guide

Curious to know the name of the effect where images scroll in a different orientation than the page, creating a 2D appearance. Take a look at the Google Nexus website and scroll down - do you see the effect? What is this effect called? Is it created usin ...

What are some strategies to optimize image loading speed in an HTML5 mobile application?

I have a HTML5 mobile application where I am loading 10 images at a time from imgur when the user clicks a button. After retrieving the images, I am applying CSS formatting to adjust the height and width for proper display on an iPhone. I suspect that the ...

Enhance the styling of elements generated through JavaScript in VueJs with custom CSS

I need help applying CSS to elements that I dynamically created using JavaScript. buttonClicked(event) { console.log(event); let x = event.clientX - event.target.offsetLeft; let y = event.clientY - event.target.offsetTop; let ripples = document.cre ...

When it comes to HTML and Javascript drawing, getting the positioning just right can be a challenge

I'm currently developing a control website for a drawing robot as part of a school project. However, I've been facing some challenges with the functionality of the drawing feature. Though I admit that the site lacks attention to detail, my main ...

Blurring the Background with CSS

Greetings! I'm attempting to achieve a background blur effect similar to the image shown. I am curious if this can be accomplished using only CSS3 or if JavaScript & Jquery are necessary for implementation: If CSS alone is sufficient, how can I ens ...

Whenever I include "border:0" in the styling of my hr element, a significant number of hr elements fail to appear on the screen

I have been experimenting with using hr elements to divide sections of my web page. Here is a snippet of the CSS code I am using: hr{ content: " "; display: block; height: .1px; width: 95%; margin:15px; background-color: #dfdfdf; ...

Horizontal line displayed in the jumbotron's footer

https://i.sstatic.net/9cjiD.jpg I'm having trouble aligning two horizontal lines (hr) in my jumbotron. The first line aligns correctly at the beginning of the page, but the second line, located at the bottom of the logo, should be at the end of the p ...

Can you help me adjust the height of my banner and center its content vertically?

Looking to create a custom banner for my website, specifically at the top with dimensions of 700px width and 80px height. The code snippet is as follows: <div class="container-narrow" style="heigth: 80px;"> <img src="#" width="52" ...

Modify the css based on the user's input

<html lang="en"> <head> <link rel="stylesheet" href="style.css" /> <li id="visa"> <section class="credit-card visa gr-visa"> <div class="logo">visa</div> <form> <h2>Payment ...

Struggling to get the font-weights of the Typography and Button components in the new React with Material-UI to display

In both my previous and most recent React applications, I have the following code snippets: <Typography variant="h6" color="inherit" noWrap > h6. Heading </Typography> <Button type="button" size="large" color="primary" > ...

When the screen becomes responsive, elements escape from the div

I'm encountering an issue with the code block below. When attempting to make the screen responsive, the elements within the aircard div are not stacking as expected. Instead, they seem to overflow. I'm unsure of the reason for this behavior and h ...

The method of stamping masonry is not encircling

I recently discovered a new method in Masonry 3 called "stamp" that allows you to fix an element in place. However, I am finding that it is not working as expected. Check out this example from David DeSandro: http://codepen.io/desandro/pen/wKpjs Initial ...

What is the best way to design a layout utilizing the "display: inline-block, block, or inline" properties in a style sheet?

https://i.sstatic.net/IqsRt.jpg Currently facing an issue with incorrect output. Code Snippet: <!DOCTYPE html> <html> <head> <style> .largebox { display: block; margin: 10px; border: 3px solid #73AD21; } .box1 { disp ...

Clicking on the overlay does not close the bootstrap collapsed toggle

I'm currently facing an issue where I need to add a listener that closes the menu when clicked away. The code snippet below shows my attempt at solving this problem: $("body").click(function(e){ var $box1 = $('.navbar-toggle'); var $b ...