Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vertically & horizontally align text after CSS rotation

Tags:

So I'm using CSS to rotate some text from horizontal to vertical (90 degrees) like so:

-webkit-transform: rotate(-90deg); -moz-transform: rotate(-90deg); writing-mode: tb-rl; filter: flipv fliph; 

My problem is that this shifts the text way outside of the container div. Is there a trick to keep it inside the container? Is there some anchor point that I could set? What is a cross browser way to adjust post?

like image 895
deweydb Avatar asked Dec 22 '11 06:12

deweydb


People also ask

What do you mean vertically?

1a : perpendicular to the plane of the horizon or to a primary axis : upright. b(1) : located at right angles to the plane of a supporting surface. (2) : lying in the direction of an axis : lengthwise.

Which way is vertically?

The terms vertical and horizontal often describe directions: a vertical line goes up and down, and a horizontal line goes across. You can remember which direction is vertical by the letter, "v," which points down.

What is an example of vertical?

The word vertical can also be used to describe the motion of objects. Since we know, vertical stands for top to bottom, the motion of an apple falling from a tree, would be vertical motion. Or the motion of a rocket or a balloon going from bottom to top is also classified as vertical.

Is there a word vertically?

theoretically | Business Englishused to say what is possible, although it may not actually happen: Theoretically, employees could be liable for the whole amount.


2 Answers

You could pull it back in with a few CSS properties...

#whatever {     position: relative;     top: -4px;     right: -10px; } 

Alternatively, you could play with the transform-origin property:

transform: rotate(-90deg); transform-origin:20% 40%; -ms-transform: rotate(-90deg); /* IE 9 */ -ms-transform-origin:20% 40%; /* IE 9 */ -webkit-transform: rotate(-90deg); /* Safari and Chrome */ -webkit-transform-origin:20% 40%; /* Safari and Chrome */ -moz-transform: rotate(-90deg); /* Firefox */ -moz-transform-origin:20% 40%; /* Firefox */ -o-transform: rotate(-90deg); /* Opera */ -o-transform-origin:20% 40%; /* Opera */ 
like image 53
alex Avatar answered Oct 14 '22 21:10

alex


Alternative method, which is more browser compliant and doesn't need information about amount of text beforehand:

.disclaimer {     position: absolute;     right: 10px;     bottom: 10px;     font-size: 12px;     transform: rotate(270deg);     -ms-transform: rotate(270deg);     -moz-transform: rotate(270deg);     -webkit-transform: rotate(270deg);     -o-transform: rotate(270deg);     line-height: 15px;     height: 15px;     width: 15px;     overflow: visible;     white-space: nowrap; } 

http://jsfiddle.net/d29cmkej/

like image 25
Rauli Rajande Avatar answered Oct 14 '22 19:10

Rauli Rajande