I have been trying text to go in a vertical direction like we can do in ms-word tables but so far I have only been able to do THIS... which I am not happy with because it's a box rotated... Isn't there a way to have actual vertical direction text?
I only set the rotation to 305 degrees in the demo which doesn't make the text vertical. 270deg will but I only made the demo to show rotation.
Alternative approach: http://www.thecssninja.com/css/real-text-rotation-with-css
p { writing-mode: tb-rl; }
-webkit-transform: rotate(90deg);
The other answers are correct but they led to some alignment problems. On trying out different things this CSS piece code worked perfectly for me.
.vertical{
writing-mode:tb-rl;
-webkit-transform:rotate(90deg);
-moz-transform:rotate(90deg);
-o-transform: rotate(90deg);
-ms-transform:rotate(90deg);
transform: rotate(90deg);
white-space:nowrap;
display:block;
bottom:0;
width:20px;
height:20px;
}
I was searching for an actual vertical text and not the rotated text in HTML as shown below. So I could achieve it by using the following method.
HTML:-
<p class="vericaltext">
Hi This is Vertical Text!
</p>
CSS:-
.vericaltext{
writing-mode: vertical-lr;
text-orientation: upright;
}
JSFiddle DEMO
======================= OLD Answer ==========================
HTML:-
<p class="vericaltext">
Hi This is Vertical Text!
</p>
CSS:-
.vericaltext{
width:1px;
word-wrap: break-word;
font-family: monospace; /* this is just for good looks */
}
JSFiddle! Demo.
Update:- If you need the whitespaces to be displayed, then add the following property to your css.
white-space: pre;
So, the css class shall be
.vericaltext{
width:1px;
word-wrap: break-word;
font-family: monospace; /* this is just for good looks */
white-space: pre;/* this is for displaying whitespaces */
}
JSFiddle! Demo With Whitespace
Update 2 (28-JUN-2015)
Since white-space: pre; doesnt seem to work (for this specific use) on Firefox(as of now), just change that line to
white-space: pre-wrap;
So, the css class shall be
.vericaltext{
width:1px;
word-wrap: break-word;
font-family: monospace; /* this is just for good looks */
white-space:pre-wrap; /* this is for displaying whitespaces including Moz-FF.*/
}
JsFiddle Demo FF Compatible.
To rotate text 90 degrees:
-webkit-transform: rotate(90deg);
-moz-transform: rotate(90deg);
-ms-transform: rotate(90deg);
-o-transform: rotate(90deg);
transform: rotate(90deg);
Also, it appears that the span tag can't be rotated without being set to display:block.
To display text in vertical (Bottom-top) we can simply use:
writing-mode: vertical-lr;
transform: rotate(180deg);
#myDiv{
text-align: center;
}
#mySpan{
writing-mode: vertical-lr;
transform: rotate(180deg);
}
<div id="myDiv">
<span id="mySpan"> Here We gooooo !!! </span>
</div>
Note we can add this to ensure Browser Compatibility:
-webkit-transform: rotate(180deg);
-moz-transform: rotate(180deg);
-ms-transform: rotate(180deg);
-o-transform: rotate(180deg);
transform: rotate(180deg);
we can also read more about writing-mode property here on Mozilla docs.
For vertical text with characters one below another in firefox use:
text-orientation: upright;
writing-mode: vertical-rl;
Try using:
writing-mode: lr-tb;
#myDiv{
text-align: center;
}
#mySpan{
writing-mode: vertical-lr;
transform: rotate(180deg);
}
<div id="myDiv">
<span id="mySpan"> Here We gooooo !!! </span>
</div>
Here is an example of some SVG code I used to get three lines of vertical text into a table column heading. Other angles are possible with a bit of tweaking. I believe most browsers support SVG these days.
<svg height="150" width="40">
<text font-weight="bold" x="-150" y="10" transform="rotate(-90 0 0)">Jane Doe</text>
<text x="-150" y="25" transform="rotate(-90 0 0)">0/0 0/0</text>
<text x="-150" y="40" transform="rotate(-90 0 0)">2015-06-06</text>
Sorry, your browser does not support inline SVG.
</svg>
I'm new at this, it helped me a lot. Just change width, height, top and left to make it fit:
.vertical-text {
display: block;
position:absolute;
width: 0px;
height: 0px;
top: 0px;
left: 0px;
transform: rotate(90deg);
}
You can also go here and see another way to do it. The author does it like this:
.vertical-text {
transform: rotate(90deg);
transform-origin: left top 0;
float: left;
}
You do with this too...
.p{
writing-mode: vertical-rl;
text-orientation: upright;
}
rotation, like you did, is the way to go - but note that not all browsers support that. if you wan't to get a cross-browser solution, you'll have to generate pictures for that.
Can use CSS3 Transform property
.txtdiv{
transform:rotate(7deg);
-ms-transform:rotate(7deg); /* IE 9 */
-ms-filter: "progid:DXImageTransform.Microsoft.Matrix(M11=0.93969262, M12=0.34202014, M21=-0.34202014, M22=0.93969262,sizingMethod='auto expand')"; /* IE6-8 */
-webkit-transform:rotate(7deg); /* Opera, Chrome, and Safari */
}
Add the class
.rotate {
-webkit-transform: rotate(-90deg);
-moz-transform: rotate(-90deg);
}
I use this pretty much everyday and not had any issues whatsoever with it.
https://css-tricks.com/snippets/css/text-rotation/
I've manage to have a working solution with this :
(I have a title within a middleItem class div)
.middleItem > .title{
width: 5px;
height: auto;
word-break:break-all;
font-size: 150%;
}
You can achieve the same with the below CSS properties:
writing-mode: vertical-rl;
text-orientation: upright;
If you want an alignement like
S
T
A
R
T
Then follow https://www.w3.org/International/articles/vertical-text/#upright-latin
Example:
div.vertical-sentence{
-ms-writing-mode: tb-rl; /* for IE */
-webkit-writing-mode: vertical-rl; /* for Webkit */
writing-mode: vertical-rl;
}
.rotate-characters-back-to-horizontal{
-webkit-text-orientation: upright; /* for Webkit */
text-orientation: upright;
}
<div class="vertical-sentence">
<p><span class="rotate-characters-back-to-horizontal" lang="en">Whatever</span></p>
<p><span class="rotate-characters-back-to-horizontal" lang="fr">Latin</span></p>
<p><span class="rotate-characters-back-to-horizontal" lang="hi">वर्डप्रेस </span></p>
</div>
Note the Hindi has an accent in my example and that will be rendered as a single character. That's the only issue I faced with this solution.
Best solution would be to use writing-mode
writing-mode: vertical-rl;
https://developer.mozilla.org/en-US/docs/Web/CSS/writing-mode
It defines whether lines of text are laid out horizontally or vertically and the direction in which blocks progress.
It has good browser support, but will not work on IE8 (if you care about IE)
http://caniuse.com/#feat=css-writing-mode
.vertical-text {
transform: rotate(90deg);
transform-origin: left top 0;
float: left;
}
<!DOCTYPE html>
<html>
<style>
h2 {
margin: 0 0 0 0;
transform: rotate(270deg);
transform-origin: top left;
color: #852c98;
position: absolute;
top: 200px;
}
</style>
<body>
<h2>It’s all in the curd</h2>
</body>
</html>
From developer.mozilla.org
The text-orientation CSS property sets the orientation of the text characters in a line. It only affects text in vertical mode (when writing-mode is not horizontal-tb). It is useful for controlling the display of languages that use vertical script, and also for making vertical table headers.
writing-mode: vertical-rl;
text-orientation: mixed;
You can also review all the Syntax here
/* Keyword values */
text-orientation: mixed;
text-orientation: upright;
text-orientation: sideways-right;
text-orientation: sideways;
text-orientation: use-glyph-orientation;
/* Global values */
text-orientation: inherit;
text-orientation: initial;
text-orientation: unset;
You can use word-wrap:break-word to get vertical text
use following snippete
HTML:
<div class='verticalText mydiv'>Here is your text</div>
css:
.verticalText {
word-wrap: break-word;
font-size: 18px;
}
.mydiv {
height: 300px;
width: 10px;
}
<style>
#text_orientation{
writing-mode:tb-rl;
transform: rotate(90deg);
white-space:nowrap;
display:block;
bottom:0;
width:20px;
height:20px;
}
</style>
</head>
<body>
<p id="text_orientation">Welcome</p>
</body>
h1{word-break:break-all;display:block;width:40px;}
H E L L O
NOTE: Browser Supported
- IE browser (8,9,10,11)
- Firefox browser (38,39,40,41,42,43,44)
- Chrome browser (44,45,46,47,48)
- Safari browser (8,9)
- Opera browser (Not Supported)
- Android browser (44)
Try using an SVG file, it seems to have better browser compatibility, and won't break your responsive designs.
I tried the CSS transform, and had much trouble with the transform-origin; and ended up going with an SVG file. It took like 10 minutes, and I could control it a bit with CSS too.
You can use Inkscape to make the SVG if you don't have Adobe Illustrator.
This works as well:
transform: rotate(90deg);
You can try like this
-webkit-transform: rotate(270deg);
-moz-transform: rotate(270deg);
-ms-transform: rotate(270deg);
-o-transform: rotate(270deg);
transform: rotate(270deg);
This is a bit hacky but cross browser solution which requires no CSS
<div>
<div>h</div>
<div>e</div>
<div>l</div>
<div>l</div>
<div>o</div>
<div>
Related
Does anyone know how to successfully implement vertical text in IE7, IE8, IE9, and IE10 with CSS only? (by vertical text, I'm referring to text being rotated counterclockwise 90 degrees)
This is what I have implemented today, which I think should be correct:
.counterclockwise-text {
/* Chrome/Safari */
-webkit-transform: rotate(-90deg);
-webkit-transform-origin: 50% 50%;
/* Firefox */
-moz-transform: rotate(-90deg);
-moz-transform-origin: 50% 50%;
/* IE9 */
-ms-transform: rotate(-90deg);
-ms-transform-origin: 50% 50%;
/* This should work for IE10 and other modern browsers that do not need vendor prefixes */
transform: rotate(-90deg);
transform-origin: 50% 50%;
/* IE8 or less - using the "\9" CSS hack so that other browsers will ignore these lines */
zoom: 1\9;
writing-mode: tb-rl\9;
filter: flipv fliph;
}
However, IE10 is not ignoring the "\9" CSS hack -- it will pick up those values and rotate the text another 90 degrees. A useful solution would be a way to do vertical text in IE8 and below that will not be picked up by IE10. I really want to avoid having an IE8-only stylesheet, or having a media query to detect IE10. I'm just looking for a way to modify the CSS above to have vertical text in all browsers. Thank you!
EDIT:
For what it is worth, I also tried the code below that uses a filter to rotate the text. This may work for most cases, but in my instance a lot of the text is cut off by the restricted (non-rotated?) constrains of the wrapping element.
.counterclockwise-text {
/* Chrome/Safari */
-webkit-transform: rotate(-90deg);
-webkit-transform-origin: 50% 50%;
/* Firefox */
-moz-transform: rotate(-90deg);
-moz-transform-origin: 50% 50%;
/* IE9 */
-ms-transform: rotate(-90deg);
-ms-transform-origin: 50% 50%;
/* IE10 and other modern browsers that do not need vendor prefixes */
transform: rotate(-90deg);
transform-origin: 50% 50%;
/* IE8 */
filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3);
/* IE7 or less */
*zoom: 1;
*writing-mode: tb-rl;
*filter: flipv fliph;
}
I still have not found a way to do this with pure CSS where IE10 and IE8 are happy.
Here is pure CSS ( + 1 extra div for every text ) solution
Works for all IE versions IE7-10
/**
* Works everywere ( IE7+, FF, Chrome, Safari, Opera )
*/
.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 doesn'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;
}
HTML example
<!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>
source: https://gist.github.com/obenjiro/7406727
You should use conditionnal comment for older IEs .
That what they are meant for and it will do no hurts nor hack (ing head) s :)
Having the same problem, but with additional bad readability of the rotated text, I would advice not to use the:
filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3);
for IE9 or IE 8.
That's, what worked for me:
p.css-vertical-text {
color:#333;
border:0px solid red;
writing-mode:tb-rl;
-webkit-transform:rotate(90deg);
-moz-transform:rotate(90deg);
-o-transform: rotate(90deg);
white-space:nowrap;
display:block;
bottom:0;
width:20px;
height:20px;
font-family: ‘Trebuchet MS’, Helvetica, sans-serif;
font-size:24px;
font-weight:normal;
text-shadow: 0px 0px 1px #333;
}
from http://scottgale.com/css-vertical-text/2010/03/01/
JSBin demo here.
How can I position a div rotated 90 degrees on the right edge of the page, centered vertically? Thanks in advance.
Try this:
div {
font-family: sans-serif;
background: red;
-webkit-transform: rotate(270deg);
-webkit-transform-origin: bottom left;
position: absolute;
width:200px;
height:20px;
top:50%;
margin-top:-20px; /* height */
right:-200px; /* width */
}
div{
vertical-align:middle;
float:right;
/* FF Chrome Opera etc */
-webkit-transform: rotate(90deg);
-moz-transform: rotate(90deg);
-o-transform: rotate(90deg);
/* IE */
filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3);
}
Check this, may help you a bit.
I have made a fiddle:
http://jsfiddle.net/89x4d/
I'm trying to maintain the skewed div but keep the p text straight.
Is this possible?
Thanks
You should use 20deg instead of 0deg on P to compensate for the DIV transform (since the result is the composition of transforms.)
In order to cancel the effect of the skew, you have to give positive value of transformation.
p {
-webkit-transform: skew(20deg) !important;
-moz-transform: skew(20deg) !important;
-o-transform: skew(20deg) !important;
transform: skew(20deg) !important;
}
Demo
div {
width: 200px;
height:50px;
background: red;
-webkit-transform: skew(-20deg);
-moz-transform: skew(-20deg);
-o-transform: skew(-20deg);
transform: skew(-20deg);
margin: 20px;
padding:0 25px;
}
p {
-webkit-transform: skew(20deg) !important;
-moz-transform: skew(20deg) !important;
-o-transform: skew(20deg) !important;
transform: skew(20deg) !important;
}
<div>
<p>hey i'm straight, ok?</p>
</div>
hey i'm straight, ok?
I'm not sure if you can get it to skew back, seems to distort the font too much.
skew(20) is the closest i could get, but instead you could setup 2 divs, 1 for a skew box and another to then move over it.
http://jsfiddle.net/gP9ne/3/
Setup a fiddle there for you to see
Martyn
edit: actually doesnt look any different :p i think its just the black on red with the font doesnt like my screen :p
always over thinking!
As others have pointed out, reversing the skew of the <p> can lead to some undesirable results.
It's also not super reusable in that for every new skew angle you would need a corresponding CSS selector/declaration to reverse the internal content.
As an alternative, use the :before selector to add the skewed element behind the text.
HTML
<div>
<p>hey i'm straight, ok?</p>
</div>
CSS
div {
width: 200px;
height:50px;
margin: 20px;
position:relative;
}
div:before {
content: "";
display:block;
background: red;
position:absolute;
width:100%;
height:100%;
z-index:-1;
-webkit-transform: skew(-20deg);
-moz-transform: skew(-20deg);
-o-transform: skew(-20deg);
transform: skew(-20deg);
}
And a demo.
I am going to ask yet another question!
So, CSS Rotate works in ie9 but getting a rotate to work in a previous version is going to be the death of me!
filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=1);
This line of code rotates elements by 90 degrees, but around the same origin as the other browsers. If the element is too close to the side of the page, it might be rotated to the outside. Microsoft's IE docs do not make it clear how to set transform origins.
My full code is:
#quick {
position:fixed;
top:250px;
left:-158px;
}
#qmenu-wrapper {
background-image: url(../images/img_08.png);
background-repeat:repeat-x;
height: 35px;
width:350px;
-webkit-transform: rotate(90deg);
-moz-transform: rotate(90deg);
-o-transform: rotate(90deg);
-ms-transform:rotate(90deg);
filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=1);
}
Is there something we can do to make IE 7 and 8 handle rotations in the same way as 9?
Thanks.
Me!
IE5.5, IE6, IE7 and IE8 are supporting filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=1);
IE5 don't support it!
Source
To change rotation origin using DX Filters just use Matrix filter to change the position of your element. You can have multiple filters on one element. You need to do a little math. Good luck with that!
Have a look at the title on the left of this site. I solved the rotation point issue by placing the item in a smaller element with overflow:visible and rotating that element. In other words I made my own pivot point.
In that example I also use writing-mode to rotate the text in IE since using filters disables font smoothing.
<style type="text/css">
/* This wrapper is required to rotate the text around the left edge */
#page_title {
overflow: visible;
position: absolute;
width: 38px;
-moz-transform: rotate(90deg);
-moz-rotation-point: 0 0;
-webkit-transform: rotate(90deg);
-webkit-rotation-point: 0 0;
-o-transform: rotate(90deg);
-ms-writing-mode: tb-lr;
* html writing-mode: tb-lr;
}
#page_title h1 {
display: block;
font-size: 70px;
font-weight: normal;
line-height: 38px;
color: #F3C1E0;
font-variant: small-caps;
width: auto;
}
</style>
<div id="page_title">
<h1>Inwardpath Publishers</h1>
</div>
I have some text in a div which is also in divs for having a double borders around it.
You can see it live here: http://jsfiddle.net/43y46/
I would like to place a text rotated 90° at bottom right of it.
Something like this:
My rotated text should be placed in the blue space on the screenshot.
Can you help me?
Thanks.
As discussed here Use this style for your text span.
.rotate {
/* Safari */
-webkit-transform: rotate(90deg);
/* Firefox */
-moz-transform: rotate(90deg);
/* IE */
-ms-transform: rotate(90deg);
/* Opera */
-o-transform: rotate(90deg);
/* Internet Explorer */
filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=1);
}
Done! :)
http://jsfiddle.net/43y46/1/
Something like this?
http://jsfiddle.net/43y46/5/
Here is my solution
<div id="content">
<div class="outer-gray">
<div class="inner-gray">
#RenderBody()
<div class="rotate">Text rotated here</div>
</div>
</div>
</div>
And the CSS
.rotate
{
position: absolute;
right: -20px;
bottom: 5px;
font-size: 10px;
color: #cccccc;
padding-top: 70px;
/* Safari */
-webkit-transform: rotate(-90deg);
/* Firefox */
-moz-transform: rotate(-90deg);
/* IE */
-ms-transform: rotate(-90deg);
/* Opera */
-o-transform: rotate(-90deg);
}