I'm trying to shift an element to the left by using transform. However, there is already an existing property on the style transform which looks like this: transform: translate3d(tx, ty, tz)
What I want to do is in addition of the translate3d(tx, ty, tz), I want to add another property called translateX(tx). So the whole style will look like this:
transform: translate3d(tx, ty, tz) translateX(tx)
Is there a way to do this in CSS? I don't want to overwrite the existing style property but add onto it.. My project is in Angular so would I have to do some code in the component end? Any help is greatly appreciated!
EDIT: I should also mention that the translate3d style is already defined for the element, not in my css file but by default (I'm using a library that sets the style for the element already). What I am trying to figure out is how to grab the current style, which is transform: translate3d AND add the translateX style to it as well so that it looks like:
transform: translate3d(tx, ty, tz) translateX(tx)
I will say it again, I do not set the translate3d in my own css file but it's a style that is automatically set for that specific element because of the library. If it helps, the library I am using is Leaflet for Angular
Update 2
No more custom variables. This example directly changes the
translate3d'sxvalue. Note: I mostly copied thegetTransformfunction from another SO post.Update
This will work and add
10pxonto the initialxtranslation in thetranslate3d:Original Answer
Instead of this pattern…
…you could set up the
translate3dproperties so they consume custom properties up front, and update the individual values as necessary.In the following example, I'm updating individual custom properties to move the box down and to the right. Note that nothing is overwritten and we have total control over the changes we'd like to make.