问题
How do i rotate text in css to get following output...
hi,Edit:
Thanks for quick suggestion. I have added my sample code in jsfidle:
http://jsfiddle.net/koolkabin/yawYM/
The problem i am facing is that when we rotate the text then it breaks the alignment and positions... so what is causing that and how can i manage them?
回答1:
You need to use the CSS3 transform property rotate
- see here for which browsers support it and the prefix you need to use.
One example for webkit browsers is -webkit-transform: rotate(-90deg);
Edit: The question was changed substantially so I have added a demo that works in Chrome/Safari (as I only included the -webkit-
CSS prefixed rules). The problem you have is that you do not want to rotate the title div, but simply the text inside it. If you remove your rotation, the <div>
s are in the correct position and all you need to do is wrap the text in an element and rotate that instead.
There already exists a more customisable widget as part of the jQuery UI - see the accordion demo page. I am sure with some CSS cleverness you should be able to make the accordion vertical and also rotate the title text :-)
Edit 2: I had anticipated the text center problem and have already updated my demo. There is a height/width constraint though, so longer text could still break the layout.
Edit 3: It looks like the horizontal version was part of the original plan but I cannot see any way of configuring it on the demo page. I was incorrect… the new accordion is part of the upcoming jQuery UI 1.9! So you could try the development builds if you want the new functionality.
Hope this helps!
回答2:
I guess this is what you are looking for?
Added an example:
The html:
<div class="example-date">
<span class="day">31</span>
<span class="month">July</span>
<span class="year">2009</span>
</div>
The css:
.year
{
display:block;
-webkit-transform: rotate(-90deg);
-moz-transform: rotate(-90deg);
filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3); //For IE support
}
Alle examples are from the mentioned site.
回答3:
In your case, it's the best to use rotate option from transform property as mentioned before. There is also writing-mode
property and it works like rotate(90deg) so in your case, it should be rotated after it's applied. Even it's not the right solution in this case but you should be aware of this property.
Example:
writing-mode:vertical-rl;
More about transform: https://kolosek.com/css-transform/
More about writing-mode: https://css-tricks.com/almanac/properties/w/writing-mode/
回答4:
You can use like this...
<div id="rot">hello</div>
#rot
{
-webkit-transform: rotate(-90deg);
-moz-transform: rotate(-90deg);
width:100px;
}
Have a look at this fiddle:http://jsfiddle.net/anish/MAN4g/
来源:https://stackoverflow.com/questions/6028128/how-do-i-rotate-text-in-css