Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rotate a <div> 90 degrees?

Tags:

html

css

I have a <div> that I want to rotate 90 degrees:

<div id="container_2"></div> 

How can I do this?

like image 890
user1808433 Avatar asked Jan 09 '13 10:01

user1808433


People also ask

How do you rotate an image 90 CSS?

We can add the following to a particular tag in CSS: -webkit-transform: rotate(90deg); -moz-transform: rotate(90deg); -o-transform: rotate(90deg); -ms-transform: rotate(90deg); transform: rotate(90deg); In case of half rotation change 90 to 45 .

How do I rotate an image 90 degrees in HTML?

Syntax: transform: rotate(90deg);

How do you write 90 degrees in HTML?

You need to add the width and height properties for the container and specify the transform property with the “rotate(90deg)” value.


1 Answers

You need CSS to achieve this, e.g.:

#container_2 {     -webkit-transform: rotate(90deg);     -moz-transform: rotate(90deg);     -o-transform: rotate(90deg);     -ms-transform: rotate(90deg);     transform: rotate(90deg); } 

Demo:

#container_2 {    width: 100px;    height: 100px;    border: 1px solid red;    -webkit-transform: rotate(45deg);    -moz-transform: rotate(45deg);    -o-transform: rotate(45deg);    -ms-transform: rotate(45deg);    transform: rotate(45deg);  }
<div id="container_2"></div>

(There's 45 degrees rotation in the demo, so you can see the effect)

Note: The -o- and -moz- prefixes are no longer relevant and probably not required. IE9 requires -ms- and Safari and the Android browser require -webkit-


Update 2018: Vendor prefixes are not needed anymore. Only transform is sufficient. (thanks @rinogo)

like image 158
Dziad Borowy Avatar answered Sep 28 '22 23:09

Dziad Borowy