2

Is there a way to display text vertically without using CSS3 and will be supported by most browsers. Currently I use image instead, but need to change to actual text.

Perhaps a combo of CSS and jQuery?

enter image description here

Erik Philips
  • 53,428
  • 11
  • 128
  • 150
santa
  • 12,234
  • 49
  • 155
  • 255
  • Have you tried googling "css vertical text"? – Blazemonger Feb 02 '12 at 18:16
  • possible duplicate of [How to draw vertical text with CSS cross-browser?](http://stackoverflow.com/questions/1080792/how-to-draw-vertical-text-with-css-cross-browser) – bjornd Feb 02 '12 at 18:16
  • What do you mean by "most browsers"? For maximum compatibility stick with your image. – j08691 Feb 02 '12 at 18:18
  • 2
    Stick with your image is a pretty bad advice, in my opinion. Increases load times, is difficult to manage, is not really semantic, is not really indexable or searchable (by the users, in the browser), increases bandwith usage, ... – ramsesoriginal Feb 03 '12 at 22:06

3 Answers3

6

My first answer would be

.element {
   -moz-transform: rotate(90deg);
   -webkit-transform: rotate(90deg) ;
   -o-transform: rotate(90deg) ;
   -ms-transform: rotate(90deg) ;
   transform: rotate(90deg);
   filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=1);
}

but you said you want to avoid css3 (A not so wise choice, in my opinion, as it would do the job well, fast, efficient and if done right across all major browsers down to IE 7... this code should do the trick)

If you really insist on javascript there's jangle ( https://github.com/corydorning/jangle ), with which you can do stuff like

 <script>
   $('.element').jangle(90);
 </script>

Ideally I would recommend doing the css3 trick, and then as a fallback using jangle. you can use http://www.modernizr.com/ for detecting the browser's ability to rotate both in CSS (through a class on the html tag) and in JavaScript.

You can even do the same for animations: CSS 2d transformation + animation if aviable, and if not, fallback to jangle.

Edit to show how selectors work:

.element is just an Example, clearly you can place any valid CSS selector, for example:

 .class {
     background-color: red;
 }
 #ID {
     background-color: green;
 }
 p {
     background-color: blue;
     color:white;
 }

 #ID .class {
     background-color: yellow;
 }

 #ID p.class {
     background-color: grey;
 }

would match elements in

<div id="ID">
    <p class="class">
        Text in a "p" with class "class" inside id "ID"
    </p>
    <p>
        Text in a "p" inside id "ID"
    </p>
    <div class="class">
        Text with class "class" inside id "ID"
    </div>
    Text inside id "ID"
</div>
<p class="class">
   Text in a "p" with class "class"
</p>
<div class="class">
   Text class "class"
</div>
<p>
   Text in a "p" 
</p>

You can see how this looks here: http://jsfiddle.net/ramsesoriginal/nXqJ2/

ramsesoriginal
  • 1,860
  • 1
  • 13
  • 16
  • .element was just a example.. You can put any valid css selector in there. I updated the question to explain this in more detail. – ramsesoriginal Feb 03 '12 at 07:26
0

Here's how to do it:

Vertical text is accomplished easily these days with CSS transforms:

.vertical-text {    
    transform: rotate(90deg);
    transform-origin: left top 0;
}

Depending on which direction you'd like the text to display vertically, the rotation will be different, but it's that rotate value which will make the text vertical. Here's a helpful tip:

.vertical-text {

    float: left;
}

Floating the element will essentially emulate an auto width!

jhoepken
  • 1,842
  • 3
  • 17
  • 24
-1

I think you can use this: http://www.w3schools.com/css3/css3_2dtransforms.asp If you put the text in a div.

Kayla
  • 309
  • 1
  • 3
  • 14
  • 3
    _without using CSS3_ as stated in the question – bjornd Feb 02 '12 at 18:17
  • 1
    I used to use w3schools for documentation as well but the Mozilla Developer Network does a much better job: https://developer.mozilla.org/en/CSS/transform – Jasper Feb 02 '12 at 18:21
  • Yes mozilla does it better, but IE below 9 does not support it... :( – santa Feb 02 '12 at 21:19
  • If you look at my answer, there's the `filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=1);` part that makes it work with IE8 (and according to some even with 7, but I never checked that. But like I already state in [my answer](http://stackoverflow.com/questions/9117625/display-text-vertically/9117872#answer-9117872) you can use CSS3 and then javascript as a fallback) – ramsesoriginal Feb 03 '12 at 12:55