11

I am trying to get a string with each individual letter rotated 90 degrees; however, I want to keep the "flow" of letters going left-to-right, not vertical. I also want to keep that "strikethrough" horizontal green line (see images below).

What's the simplest way to accomplish this? I prefer using JavaScript and/or CSS.

With the -transform: rotate CSS style I get the following:

do not want

<style type="text/css">
.rotate {
-webkit-transform: rotate(-90deg);
}
</style>
<body>
<div class="rotate">
<span style="color:#0C0; text-decoration:line-through;">
<span style="color:#000;">
A B C
</span></span></div>

What I would like to get is something like this, without resorting to a custom font.

enter image description here

| improve this question | |
10

Pure CSS:

<div class="letters">
    <span>A</span><span>B</span><span>C</span>
</div>​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​

.letters {
    height:8px;
    line-height:16px;
    border-bottom:1px solid green;
    position:relative;
}
.letters > span {
    float:left;
    -webkit-transform: rotate(-90deg);
}​

Demo

| improve this answer | |
4

Here's some js that should do the trick: http://jsfiddle.net/AYGDR/8/

$(function() {
    $(".target").html(("<span>" + $(".target").html().split(" ").join("</span><span>") + "</span>"));
    var rotate = 0;
    $(".target span").each(function() {
        rotate = rotate - 90
        $(this).css({
            "-webkit-transform": "rotate(" + rotate + "deg)",
            "display": "inline-block"
        });
    });
});

And I accidentally threw in some bonus shifting rotation since I imagined that was part of the question.

| improve this answer | |
3

my CSS:

<style>
span[class^="rot"]:not([char]):before{
content: '\27b7'; }
span[class^="rot"][char]:before{content: attr(char);}
span[class^="rot"] { position: relative; }
span[class^="rot"]:before {
 position: relative; display: inline-block;
 font-weight: bold; font-size: 16px; line-height:16px;
 font-family: Tahoma, Verdana, sans-serif;
 margin:0;padding:0;
 width:16px;height:16px;
}
.rot-90:before { transform: rotate(-90deg); }
.rot90:before  { transform: rotate(90deg); }
.rot45:before { transform: rotate(45deg); }
.rot-45:before { transform: rotate(-45deg); }
.rot180:before { transform: rotate(180deg); }
</style>
<p>
A long time <span class=rot90 style="color: green"></span> ago  in a  
<span class=rot-45 char="G"></span>alax<span class=rot180 char="y"></span> 
&nbsp; <span class=rot-90 char="F"></span>ar far 
a<span class=rot45 char="w"></span>way

result

| improve this answer | |
0

This works in latest version of chrome

<span style="color:#000; display: inline-block; max-width: 10px;">
A B C
</span>

only wrote the innermost span though

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.