Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS: Right align a vertically rotated text

I can't seem to align a vertically rotated div all the way to the right side of the page: http://jsfiddle.net/F23W2/2/

HTML:

<div class="vertical">Vertical Text</div>

CSS:

.vertical {
    position: relative;
    background-color: #DDDDDD;
    padding: 10px;
    border-radius: 5px 5px 0 0;
    float: right;
    -moz-transform: rotate(270deg);  /* FF3.5+ */
    -o-transform: rotate(270deg);  /* Opera 10.5 */
    -webkit-transform: rotate(-90deg);  /* Saf3.1+, Chrome */
} 
  • There is unwanted margin created between right page border and the div.
  • Top part of rotated div gets cropped.

Although I can use negative margins to work around, I was wondering if a cleaner solution exists.

like image 893
rajivRaja Avatar asked Sep 03 '13 20:09

rajivRaja


People also ask

How do I align text vertically in CSS?

Use the CSS line-height property Add the line-height property to the element containing a text larger than its font size. By default, equal spaces will be added above and below the text, and you'll get a vertically centered text.

How do you vertically align elements in CSS?

The vertical-align property in CSS controls how elements set next to each other on a line are lined up. In order for this to work, the elements need to be set along a baseline. As in, inline (e.g. <span> , <img> ) or inline-block (e.g. as set by the display property) elements.


1 Answers

Change the origin of the rotation transform via transform-origin: 100% 100%;

body {
  padding: 0;
  margin: 0;
}

.vertical {
  position: relative;
  background-color: #DDDDDD;
  padding: 10px;
  border-radius: 5px 5px 0 0;
  float: right;
  -moz-transform: rotate(270deg);
  /* FF3.5+ */
  -o-transform: rotate(270deg);
  /* Opera 10.5 */
  -webkit-transform: rotate(-90deg);
  /* Saf3.1+, Chrome */
  -moz-transform-origin: 100% 100%;
  -o-transform-origin: 100% 100%;
  -webkit-transform-origin: 100% 100%;
}
<div class="vertical">Vertical Text</div>

New Fiddle

like image 177
BigMacAttack Avatar answered Oct 24 '22 07:10

BigMacAttack