Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flip / mirror an image horizontally + vertically with css

Im trying to flip an image to display it 4 ways : original (no changes), flipped horizontally, flipped vertically, flipped horizontally + verticly.

To do this Im doing the below, it works fine apart from the flip horizontally + vertically, any idea why this wouldnt be working ?

Ive made a JS fiddle of the issue here : https://jsfiddle.net/7vg2tn83/

.img-hor {         -moz-transform: scaleX(-1);         -o-transform: scaleX(-1);         -webkit-transform: scaleX(-1);         transform: scaleX(-1);         filter: FlipH;         -ms-filter: "FlipH"; }  .img-vert {         -moz-transform: scaleY(-1);         -o-transform: scaleY(-1);         -webkit-transform: scaleY(-1);         transform: scaleY(-1);         filter: FlipV;         -ms-filter: "FlipV"; }  .img-hor-vert {         -moz-transform: scaleX(-1);         -o-transform: scaleX(-1);         -webkit-transform: scaleX(-1);         transform: scaleX(-1);         filter: FlipH;         -ms-filter: "FlipH";          -moz-transform: scaleY(-1);         -o-transform: scaleY(-1);         -webkit-transform: scaleY(-1);         transform: scaleY(-1);         filter: FlipV;         -ms-filter: "FlipV"; } 
like image 787
sam Avatar asked Sep 30 '15 21:09

sam


People also ask

How do I flip an image vertically in CSS?

Reversing the orientation of images is very easy with CSS, if somewhat counter-intuitive for those not mathematically inclined: to flip an image, you use a value of -1 with the CSS transform properties scaleX or scaleY , depending on whether you wish to flip the element horizontally or vertically.

How do you flip an image horizontally and vertically?

How do I flip my image? To flip an image or icon, simply: Select the object you would like to flip. Right click on that object, and select 'Flip Horizontal' or 'Flip Vertical'.”

How do you mirror an image in CSS?

You may do a transform: rotate(180deg); for the horizontal+vertical flip. This would only work on symmetrical images. Since you'd be rotating and not flipping the image. E.g.: take the letter (d).


1 Answers

Try this:

.img-hor-vert {     -moz-transform: scale(-1, -1);     -o-transform: scale(-1, -1);     -webkit-transform: scale(-1, -1);     transform: scale(-1, -1); } 

Updated fiddle: https://jsfiddle.net/7vg2tn83/1/

It wasn't working before because you were overriding the transform in your css. So instead of doing both, it just did the last one. Sort of like if you did background-color twice, it would override the first one.

like image 158
pgruber Avatar answered Sep 19 '22 21:09

pgruber