Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What does 2 declarations of `translate` keyword inside of CSS transform property mean? Ex: `transform: translate() translate()`

I recently stumbled upon some CSS code using transform css property using 2 translate values inside of the transform. I am not sure exactly how to interpret this:

transform: translate(-50%, -50%) translate(200px, 40px)`,

I had trouble finding any examples on the MDN docs or top hits on google.

Do the transforms override each other, are these like stacking values?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I’ve seen transform property used like this before:

/* Function values */
.some-class {
  transform: translate(10px, 10px)
}
.some-class {
  transform: translateX(10px) 
}
.some-class {
  transform: translateY(10px) 
}
/* Multiple function values */
.some-class {
   transform: translateX(10px) rotate(10deg) translateY(5px);
}

References

>Solution :

It’s one translation applied after another. In the case of translate(-50%, -50%) translate(200px, 40px), it’s first moving to -50% of the range, then after it reaches that position, it’s offset by an additional 200px, 40px.

You can stack CSS transforms like this. You can also easily test this in the MDN site you linked, by editing the translate example to add another one, and observe the behavior.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading