1

How to rotate a text (cross browser) ? my code works in FireFox, Opera :(

I WANT TO ROTATE TEXT ON IE TOO (_Rotation degree can be any degree within 15 and 60)

<html>
<head>
<style type="text/css">

#memo
{
width:200px;
word-wrap: break-word;
background-color:yellow;
}
</style>
</head>

<body>
<php
$deg=rand(15,60);
?>

<div id="memo" style="transform:rotate(<?php echo $deg; ?>deg); -moz-transform:rotate(<?php echo $deg; ?>deg);-webkit-transform:rotate(<?php echo $deg; ?>deg);-o-transform:rotate(<?php echo $deg; ?>deg);">Hello</div>
</body>

</html>
5
  • All your code block are belong to us. Commented Apr 2, 2011 at 8:01
  • It should work in Safari/Chrome and Opera as well. Commented Apr 2, 2011 at 8:04
  • @icktoofay i need to do it in IE Commented Apr 2, 2011 at 8:06
  • 1
    @Sourav, You will learn in due time my young grasshopper. Commented Apr 2, 2011 at 8:07
  • 1
    @Nick ok my senior grasshopper. Commented Apr 2, 2011 at 8:08

4 Answers 4

2

Seems to work OK in all modern browsers (not IE) for me.

Demo: turi.co/up/rand_rotate

<?php $deg=rand(15,60); ?>
<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>Random transform:rotate</title>
        <style type="text/css">
            #memo {
                width:5em; word-wrap:break-word; margin:2em;
                font:700 3em/1.2 'myriad pro', sans-serif;
                transform:rotate(<?php echo $deg; ?>deg);
                -o-transform:rotate(<?php echo $deg; ?>deg);
                -moz-transform:rotate(<?php echo $deg; ?>deg);
                -webkit-transform:rotate(<?php echo $deg; ?>deg);
            }
        </style>
    </head>
    <body>
        <div id="memo">Hello</div>
    </body>
</html>
Sign up to request clarification or add additional context in comments.

1 Comment

IE may or may not be "modern", but it is the market leader. A solution that doesn't work in the most common browser isn't really a solution...
0

These 3 rules will make the non IE browsers rotate.

-webkit-transform: rotate(90deg);
-moz-transform: rotate(90deg);   
-o-transform: rotate(90deg);

For IE, you could use filters. I've seen a -ms-transform somewhere, but can't seem to find it right now.

Filter usage : http://snook.ca/archives/html_and_css/css-text-rotation

1 Comment

0

http://snook.ca/archives/html_and_css/css-text-rotation

-webkit-transform: rotate(-90deg); 
-moz-transform: rotate(-90deg); 
For Opera -> -o-transform support in 10.50
For IE -> filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3);

To rotate 45 in IE


filter: progid:DXImageTransform.Microsoft.Matrix(sizingMethod='auto expand', M11=0.7071067811865476, M12=-0.7071067811865475, M21=0.7071067811865475, M22=0.7071067811865476); /* IE6,IE7 */
-ms-filter: "progid:DXImageTransform.Microsoft.Matrix(SizingMethod='auto expand', M11=0.7071067811865476, M12=-0.7071067811865475, M21=0.7071067811865475, M22=0.7071067811865476)"; /* IE8 */

3 Comments

in IE i can rotate for 90,180,270 degrees, but i can't rotate for 45 or 90 degree !
how to calculate the matrix values??
@AnandThangappan, see Rotation Matrix
0

Use the excellent jQuery Rotate plugin. http://code.google.com/p/jqueryrotate/. It is supported by all major browsers

* Internet Explorer 6.0 >
* Firefox 2.0 >
* Safari 3 >
* Opera 9 >
* Google Chrome 

To rotate an image, All you need to do is $('#myImage').rotate(30) //for a 30 degree rotation Where #myImage is the id of the element you want rotated.


If all you want to do is rotate text vertically, you can use simple CSS without much effort.

<h1 id="heading">t e x t</h1>

#heading {
 color:#66CCFF;
 font-size:50px;
 width:0.5em;
}

Check working example at http://jsfiddle.net/u4Wd2/

1 Comment

Dear Hussein, jQuery Rotate plugin only supports for images not for text :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.