Hello!
To achieve that, we can employ scale() CSS function:
transform: scale() with negative scaling.
Syntax:
transform: scale(bothAxesScaling)
Or:
transform: scale(horizontalScaling, verticalScaling)
bothAxesScaling, horizontalScaling, and verticalScaling can be numbers or percentages.
For example:
There are also scaleX() and scaleY(). They are dedicated to each axis.
-
transform: scaleX(number or percentage)Scales the element along the horizontal (x) axis.
-
transform: scaleY(number or percentage)Scales the element along the vertical (y) axis.
In this post, let's simply try the scale() function.
Let's Try
I have a penguin image:
Then I flip the image horizontally:
➡️
Or I flip it vertically:
➡️
For our information, img element is displayed inline by default. Therefore, we need to explicitly redefine it as inline-block. Since display: inline will not work with scale() function.
The HTML goes as such:
This is what happens if we use both classes. ⬇️
➡️
Well. That.
The .y-mirror class overrides the .x-mirror one. ⬇️
Text
We can also use this method to play around with text — as long as we wrap the text with a display: inline-block or display: block element.
Er, essentially we will play with the wrapper element, not the text. But the text will be inside the element. So. ðĪ Hm.
Anyway.
Like this, the original text:
Flip it horizontally:
Flip it vertically:
The HTML:
The CSS transform
The CSS transform property has a pivot point or origin, called —
If we don't define it, by default, transform will use the centre of the element.
Related Tool
I've made an emoji transformer tool on Port Raptor. You may want to try it. ⬇️
Thanks for visiting!
