Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rotate + flip element with CSS

The transform property lets you rotate or flip, but how can you do both at the same time? Say I want to rotate an element 90 degrees and flip it horizontally? Both are done with the same property, so the latter overwrites the former. Here's an example fiddle for convenience:

http://jsfiddle.net/DtNh6/

transform: rotate(90deg); transform: scaleX(-1); 
like image 304
chinabuffet Avatar asked Jun 10 '13 00:06

chinabuffet


People also ask

How do you flip an element in CSS?

We can flip the img element using the CSS transform property. We can do so using the scaleX and scaleY transforms. The CSS to flip it. The rotation transform is also a nice choice for when you want to animate the flip.

How do you flip horizontal in CSS?

You may do a transform: rotate(180deg); for the horizontal+vertical flip.


2 Answers

I fiddled with jsfiddle, and this worked:

$('#photo').css('transform', 'rotate(90deg) scaleX(-1)'); 

To relate it to your question, the resulting CSS looks like

transform: rotate(90deg) scaleX(-1); 
like image 63
James Green Avatar answered Sep 19 '22 20:09

James Green


The properties can be delimited by spaces, like so.

transform: rotate(90deg) scaleX(-1); 
like image 44
Austin Brunkhorst Avatar answered Sep 20 '22 20:09

Austin Brunkhorst