I have an element with a ton of CSS transformations like this:
transform: translateX( 0 )
translateY( -1rem )
rotate( 45deg )
translateY( -2.5rem )
rotate( 45deg )
translateY( 5rem );
The order of these properties matter as they affect how the element ends up being positioned on the page. I've done some tinkering and came up with the same exact end result with fewer properties:
transform: rotate( 90deg ) translateX( -2.8rem ) translateY( 3.25rem );
You can test this by commenting and uncommenting out the comment in the snippet below to see nothing changes ( the transformations equal the same result ).
I did this manually and it took some time to find the exact transformations that would get me the same result. I'm trying to do this for literally thousands of properties in real time...
Is there a formula? Is there a CSS hack? Is there a simple way of doing this - I don't know where to start. O.o
html {
display: flex;
height: 100%;
justify-content: center;
align-items: center;
}
div {
padding: 2.5rem 1rem;
background-color: #4cc;
color: #eee;
text-align: center;
border: 1px solid #eee;
border-radius: 0.25rem;
transform: translateX( 0 )
translateY( -1rem )
rotate( 45deg )
translateY( -2.5rem )
rotate( 45deg )
translateY( 5rem );
/*transform: rotate( 90deg ) translateX( -2.8rem ) translateY( 3.25rem );*/
}
<div>
transformed<br>element
</div>
Edit: You might be wondering: Why do this!? Well here is a problem I had earlier: Move transform-origin back to the center of the element in CSS. I solved it like this: Transforms are added...endlessly . But now I have endless transforms and this is why I ask.
I have tons of dynamic transforms that look like this: