Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rotating only the text (not the div) in a div element

Tags:

html

text

css

I am trying to create a webpage with a lot of div elements whose positions and size are created separately. Next, I want to insert text into those elements so I use JS to put the text in the innerHTML. Is there a way here that I can rotate just the text by 90degrees (and not the div itself since I don't want to change the position and orientation of the div elements?

I tried -webkit-transform: rotate(-90deg); -moz-transform: rotate(-90deg); in CSS but they all rotate the divs themselves and not just the text.

Any idea if this is possible.

Thanks!

like image 773
Devang Avatar asked May 13 '11 06:05

Devang


People also ask

Can we rotate a div?

An element can be rotated 90 degrees by using the transform property. This property is used to move, rotate, scale and others to perform various kinds of transformation to elements.

How do you rotate elements?

The CSS rotate() function lets you rotate an element on a 2D axis. The rotate() function accepts one argument: the angle at which you want to rotate your web element. You can rotate an element clockwise or counter-clockwise.


2 Answers

I have not tried this, but why not include an extra <div> between your current <div> and your text, with a transparent background? You can then rotate that <div>.

like image 53
TNi Avatar answered Oct 05 '22 23:10

TNi


Wrap the text in a span and set it to inline-block. Notice how the parent div doesn't not rotate together with the text.

<div class="roundedOne">
  <span class="rotate">TEXT</span>
</div>

.rotate {
  display: inline-block;
  transform: rotate(-90deg); 
  -moz-transform: rotate(-90deg);
}

.roundedOne {
  background: red;
}

CODEPEN

http://codepen.io/alexincarnati/pen/JEOKzw

like image 28
Alessandro Incarnati Avatar answered Oct 06 '22 01:10

Alessandro Incarnati