Skip to content

Instantly share code, notes, and snippets.

@obenjiro
Last active April 4, 2020 20:23
Show Gist options
  • Select an option

  • Save obenjiro/7406727 to your computer and use it in GitHub Desktop.

Select an option

Save obenjiro/7406727 to your computer and use it in GitHub Desktop.
CrossBrowser Vertical CSS Text
/**
* Works everywere ( IE7+, FF, Chrome, Safari, Opera )
* Example: http://jsbin.com/afAQAWA/2/
*/
.rotated-text {
display: inline-block;
overflow: hidden;
width: 1.5em;
}
.rotated-text__inner {
display: inline-block;
white-space: nowrap;
/* this is for shity "non IE" browsers
that dosn't support writing-mode */
-webkit-transform: translate(1.1em,0) rotate(90deg);
-moz-transform: translate(1.1em,0) rotate(90deg);
-o-transform: translate(1.1em,0) rotate(90deg);
transform: translate(1.1em,0) rotate(90deg);
-webkit-transform-origin: 0 0;
-moz-transform-origin: 0 0;
-o-transform-origin: 0 0;
transform-origin: 0 0;
/* IE9+ */
-ms-transform: none;
-ms-transform-origin: none;
/* IE8+ */
-ms-writing-mode: tb-rl;
/* IE7 and below */
*writing-mode: tb-rl;
}
.rotated-text__inner:before {
content: "";
float: left;
margin-top: 100%;
}
/* mininless css that used just for this demo */
.container {
float: left;
}
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<div class="container">
<div class="rotated-text"><span class="rotated-text__inner">Easy</span></div>
</div>
<div class="container">
<div class="rotated-text"><span class="rotated-text__inner">Normal</span></div>
</div>
<div class="container">
<div class="rotated-text"><span class="rotated-text__inner">Hard</span></div>
</div>
</body>
</html>
@psgganesh

Copy link
Copy Markdown

Thank you :) this saved my day 💯

@benjaminokeefe

Copy link
Copy Markdown

Thank you, the -ms-writing-mode: tb-rl; line works like a charm for IE8.

@neo1992

neo1992 commented Apr 24, 2015

Copy link
Copy Markdown

I tried changing "90deg" to "270deg" to have the text rotate the other way, but that only works in Chrome (where the text is unfortunately also moved outside the outer container) and not in IE11. How can I configure this to have the text the other way around?

@anyone1997

Copy link
Copy Markdown

Thanks! Will use it!

@JAC2703

JAC2703 commented Oct 2, 2015

Copy link
Copy Markdown

+1

@dhwang

dhwang commented Oct 12, 2015

Copy link
Copy Markdown

writing mode are in Chrome and Firefox now

https://developer.mozilla.org/en-US/docs/Web/CSS/writing-mode

@RobMKR

RobMKR commented Oct 17, 2016

Copy link
Copy Markdown

Thanks a lot man)))

ghost commented Dec 28, 2016

Copy link
Copy Markdown

Thanks! Work in ie7, ie8 : )

@andru1989

Copy link
Copy Markdown

Thanks man

@john-doherty

Copy link
Copy Markdown

TY!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment