What is the proper way to incorporate transform-origin into CSS for the scenario provided below?

*{
  padding:0;
  margin:0;
  border: 1px solid blue;
}
 
#container{
  margin: 10rem;
  position:fixed;
}

.inner{
  animation: animate-inner 5s linear infinite;
}

@keyframes animate-inner{
  0%{
    transform-origin: 20% 20%;
    transform: rotate(0);
  }
  100%{
    transform-origin: 20% 20%;
    transform: rotate(360deg);
  }
}

.inner2{
  animation: animate-inner2 7s linear infinite;
}

@keyframes animate-inner2{
  0%{
    transform-origin: 50% 50%;
    transform: rotate(0);
  }
  100%{
    transform-origin: 50% 50%;
    transform: rotate(180deg);
  }
}
<div id="container">
  <svg height = "500" width="500">
    <circle class="outer" cx="100" cy="100" r = "100"/>
    <circle class="inner" cx="93.5" cy="12.5" r = "12.5" fill="red"/>
    <circle class="outer" cx="400" cy="100" r = "100"/>
    <circle class="inner2" cx="393.5" cy="13.5" r = "12.5" fill="red"/>
  </svg>
</div>

Need guidance on utilizing the transform-origin property in CSS. Despite reading MDN, there's confusion regarding its application in this scenario. Seeking advice for making the inner circle revolve around both outer circles simultaneously. Any assistance is appreciated.

Answer №1

It seems that the usage of transform-origin is causing some complications here. I decided to simplify things by introducing a <g> element as a parent to each inner circle, which helps in centering the circles within the outer circles. The use of cx then acts as an "arm" to position them.

*{
  padding:0;
  margin:0;
  border: 1px solid blue;
}
 
#container{
  margin: 10rem;
  position:fixed;
}

.inner{
  animation: animate-inner 5s linear infinite;
}

@keyframes animate-inner{
  0%{
    transform: rotate(0);
  }
  100%{
    transform: rotate(360deg);
  }
}
<div id="container">
  <svg height="500" width="500">
    <circle class="outer" cx="100" cy="100" r="100"/>
    <g transform="translate(100 100)">
      <circle class="inner" cx="87.5" r="12.5" fill="red"/>
    </g>
    <circle class="outer" cx="400" cy="100" r="100"/>
    <g transform="translate(400 100)">
      <circle class="inner" cx="87.5" cy="0" r="12.5" fill="blue"/>
    </g>
  </svg>
</div>

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

The process of redirecting a web page using htaccess and incorporating URL parameters

I have a directory where I store HTML pages. Using the PHP include function, I am adding these pages to my index.php file by referencing them with a URL parameter value. The URL parameter "xpage" corresponds to the page names stored in another folder, whil ...

Having trouble with the ::after element in my React component for my latest React 3D portfolio project

For my portfolio project, I am following a tutorial by LamaDev (https://www.youtube.com/watch?v=qALsVa-V9qo&t=2334s&ab_channel=LamaDev). At around timestamp 36:40, he creates a ::after selector which is not working for me, even though the rest of t ...

Issues with the performance of input range sliders in iOS Safari is causing frustration

I recently developed a basic range slider component for an application built with NextJS. This component utilizes an <input type="range"> element. While the range slider functions properly on Desktop and Android devices, I encountered sign ...

Running the NPM build command results in an error specifically related to an HTML file

I encountered an issue in my AngularJS application when running the command: npm run build -- -prod The error message I received was: ERROR in ng:///home/directoryling/appname-play.component.html (173,41): The left-hand side of an arithmetic operation ...

Having trouble locating the code for adding a hover effect to the FontAwesome icon

In regards to my portfolio located here: My Portfolio When hovering over the "Marketing Automation" section, a small fa fa-tablet icon appears to the left which turns blue when hovered over. I would like for this icon to remain white, rather than changing ...

Position elements to the right side of a flex container

I'm utilizing Bootstrap 4 along with this CSS class to vertically align my elements: .vertical-align { display: flex; flex-direction: row; } .vertical-align > [class^="col-"], .vertical-align > [class*=" col-"] { display: flex; align-i ...

No matter what, the Django authenticate function will consistently return None

I have been facing challenges in implementing registration/login/logout functionality. While user registration is successful and the user data appears in Django admin as well as in the database, I am encountering issues with the login functionality. Upon c ...

In every browser except for Safari on iPad, a white X is displayed in the grey box. I'm wondering if the error lies with me or with Safari

When using Safari on my iPad, I noticed that the white X appears on the right-hand side of the black screen. Since this is the only version of Safari that I have, I am unsure if this issue is specific to iPads, Safaris, or just my device. Visit this link ...

Can we stop a specific container from resizing on mobile devices?

My goal is to have the entire page scale down, except for the navigation container. I'm adjusting some CSS rules to improve accessibility on smartphones, but the issue arises with the multiple images it uses. I need these images to display in their or ...

"Unlocking the Power of mediaElementjs: Easy Steps to Accessing the Player Instance

I'm facing a small issue with the MediaElement.js player. To access the player instance, I usually use the following code (which works in HTML5 compatible browsers): // Retrieve player this.playerId = $('div#shotlist-player video').att ...

What could be the reason for the improper display of this?

I am in the process of creating an e-commerce website where users can add products to their virtual shopping carts. However, I am facing an issue with displaying the correct button ('Add to Cart' or 'Remove from Cart') based on whether ...

using an id= instead of a href=

I have an organized list with links, but when I add a link that requires a specific ID, the CSS is not applied to it. Since the CSS only targets li a:link{}, how can I make it recognize the specified ID too? The ID 'swishLink' is used in multip ...

Generate and save (html/css/js) files directly on the client's browser

Recently, I created a code playground using React similar to liveweave. Users can save their "code playgrounds" and access them later by utilizing Firebase for the database. These "code playgrounds" consist of HTML, CSS, and JavaScript elements. My goal no ...

Outcome of Request.Form when the input requested is empty

What can I do when Request.Form("myInput") is blank and causes a server error? Any suggestions on how to address this issue? Is there a method to verify if "myInput" has not been populated? ...

"Interact with jQuery by sliding side to side or in a circular motion

I am in need of assistance with sliding images using jQuery back and forth, or making them go round in a loop. Currently, the images slide up to the last element and then swiftly return to the first div, which is not visually appealing at all. I understa ...

Is it possible to have both a Navbar and Sidebar concurrently using Bootstrap?

I have a slightly unconventional request - I want to incorporate the sidebar from along with the navbar-default example from http://getbootstrap.com/components/#nav. What would be the best approach to merge these two elements? Or is there a different pa ...

Upon entering, clear the contents and bring the focus to the textarea

Whenever I press the enter key, I want to clear and focus on a textarea. I thought I had written the correct code, but sometimes the textarea gets cleared without focusing, and other times it focuses without clearing. I have tried many different codes, but ...

Tips for Positioning Ant Design Select Dropdown Anchor to the Right of the Select Component

Currently, I am utilizing Ant Design in my project and encountering an issue with a Select component. The Select is positioned to the right side of the screen and contains labels that are quite long. This causes the dropdown to overflow and a scrollbar t ...

Video player on website experiencing issues with playing VAST ads

Hey there! Check out this awesome site for Music Videos: (Music Videos(Player)) I've been testing different options, but if you have a better suggestion, please let me know. Any help would be really appreciated. If I can't figure it out on my o ...

Ensure that the background-color stretches across the entire width of the screen

This text needs to be centered and the background color width should cover the entire screen. Unfortunately, I couldn't find a solution for it here. .carousel-content { text-align: center; bottom: 0px; opacity: 0.8; displ ...