CSS3 transform: rotate; in IE9
Asked Answered
L

5

77

I have an element that needs to be vertical in a design I have done. I have got the css for this to work in all browsers except IE9. I used the filter for IE7 & IE8:

progid:DXImageTransform.Microsoft.BasicImage(rotation=3);

This however seems to render my element transparent in IE9 and the CSS3 'tranform' porperty doesn't seem to do anything!

Does anyone know anyway of rotating elements in IE9?

Really appreciate the help!

W.

Ledoux answered 1/2, 2011 at 16:28 Comment(0)
H
139

Standard CSS3 rotate should work in IE9, but I believe you need to give it a vendor prefix, like so:

  -ms-transform: rotate(10deg);

It is possible that it may not work in the beta version; if not, try downloading the current preview version (preview 7), which is a later revision that the beta. I don't have the beta version to test against, so I can't confirm whether it was in that version or not. The final release version is definitely slated to support it.

I can also confirm that the IE-specific filter property has been dropped in IE9.

[Edit]
People have asked for some further documentation. As they say, this is quite limited, but I did find this page: http://css3please.com/ which is useful for testing various CSS3 features in all browsers.

But testing the rotate feature on this page in IE9 preview caused it to crash fairly spectacularly.

However I have done some independant tests using -ms-transform:rotate() in IE9 in my own test pages, and it is working fine. So my conclusion is that the feature is implemented, but has got some bugs, possibly related to setting it dynamically.

Another useful reference point for which features are implemented in which browsers is www.canIuse.com -- see http://caniuse.com/#search=rotation

[EDIT]
Reviving this old answer because I recently found out about a hack called CSS Sandpaper which is relevant to the question and may make things easier.

The hack implements support for the standard CSS transform for for old versions of IE. So now you can add the following to your CSS:

-sand-transform: rotate(10deg);

...and have it work in IE 6/7/8, without having to use the filter syntax. (of course it still uses the filter syntax behind the scenes, but this makes it a lot easier to manage because it's using similar syntax to other browsers)

Hasp answered 1/2, 2011 at 16:38 Comment(11)
Thanks Spud! I'm gonna check it out now and get back to you on that. Couldn't believe how little documentation there was about this online.Ledoux
@Hasp Could you post a source? I am not able to find that on MSDN msdn.microsoft.com/en-us/library/ms531207(v=vs.85).aspxLouannlouanna
@Šime Vidas and @pagewil - you're right, not much documentation around. I found it documented here: css3please.com, though I should note that this page crashed my copy of IE9 preview when I tried to use the rotate property. However, my own independant tests have confirmed that the property does work, with the vendor prefix as I've quoted in my answer. (given the crash, I guess there are still bugs in it though!)Hasp
I really don't get why rotate need a vendor prefix, when they go standard with the rest of CSS3Bypass
@Eduardo - possibly because the standard hasn't been finalised yet?Hasp
@Spudley: yeah, but isn't finalized for the other properties eitherBypass
@Eduardo - shrug I dunno. It's up to the vendors really to decide whether they're ready in their browser for the feature to drop the prefix. It seems like it's stable, but transform covers a lot of stuff, so maybe there's still some debate at W3C about some aspect of it? Whatever, each vendor needs to make that decision when they feel they're ready.Hasp
Unfortunately they don't support rotateX, rotateY -_-. Just the plain rotateZ which is implied by rotate().Severen
I am getting nothing from any of these rules in IE9 for rotateLuis
@alex_b - the most likely reason for that is if it's running in compatibility mode. Check the mode by pressing F12 to bring up the dev tools.Hasp
Also, pay attention on the crossbrowser line that must be excluded for IE9+: filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3)Jala
A
5

Try this

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
body {
    margin-left: 50px;
    margin-top: 50px;
    margin-right: 50px;
    margin-bottom: 50px;
}
.rotate {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 16px;
    -webkit-transform: rotate(-10deg);
    -moz-transform: rotate(-10deg);
    -o-transform: rotate(-10deg);
    -ms-transform: rotate(-10deg);
    -sand-transform: rotate(10deg);
    display: block;
    position: fixed;
}
</style>
</head>

<body>
<div class="rotate">Alpesh</div>
</body>
</html>
Asquith answered 1/4, 2013 at 5:6 Comment(1)
i try this code with ie9, FireFox, Chrome, Safari & it's workAsquith
M
4

I also had problems with transformations in IE9, I used -ms-transform: rotate(10deg) and it didn't work. Tried everything I could, but the problem was in browser mode, to make transformations work, you need to set compatibility mode to "Standard IE9".

Moderator answered 11/6, 2012 at 10:58 Comment(3)
press f12 in ie and select change browser mode to ie-9 and then check this will work...Schreibman
For IE9 to work with vertical text, you have to turn off quirks mode by using the following as the first two lines of your file: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">Rosenberger
Any valid doctype should disable quirks mode, eg: <!DOCTYPE html>. The browser mode should be IE9 by default, unless you've changed your settings.Hanway
T
3

I know this is old, but I was having this same issue, found this post, and while it didn't explain exactly what was wrong, it helped me to the right answer - so hopefully my answer helps someone else who might be having a similar problem to mine.

I had an element I wanted rotated vertical, so naturally I added the filter: for IE8 and then the -ms-transform property for IE9. What I found is that having the -ms-transform property AND the filter applied to the same element causes IE9 to render the element very poorly. My solution:

  1. If you are using the transform-origin property, add one for MS too (-ms-transform-origin: left bottom;). If you don't see your element, it could be that it's rotating on it's middle axis and thus leaving the page somehow - so double check that.

  2. Move the filter: property for IE7&8 to a separate style sheet and use an IE conditional to insert that style sheet for browsers less than IE9. This way it doesn't affect the IE9 styles and all should work fine.

  3. Make sure to use the correct DOCTYPE tag as well; if you have it wrong IE9 will not work properly.

Toscana answered 2/9, 2014 at 19:42 Comment(1)
Good call on -ms-transform-origin; that had me scratching my head for a while.Zachery
R
0

Can use:

 element.style['-ms-transform']='translate...'
Reynold answered 30/5, 2021 at 11:44 Comment(1)
Why do you prefer this over the accepted answer? On that note, the accepted answer also offers an excellent example of the level of detail and explanation that the most useful and timelines answers on Stack Overflow have; that's something to strive for.Diehard

© 2022 - 2024 — McMap. All rights reserved.