Follow @endyourif rss Facebook LinkedIn

Rotating DOM Elements using CSS Rotating DOM Elements using CSS

Published on Mar 7, 2019

Modern browsers and CSS3 begins to allow us much more freedom using standard text without the need of images. Not only does this speed up page load times, it also lowers bandwidth costs as well. Using CSS3, many standard DOM (Document Object Model) objects can easily be rotated, such as: images, text, block elements, etc…

Let's explore how we can use the transform CSS property to accomplish this.

To begin, some basic HTML is required before we can apply the CSS code to it. In the example below, I will demonstrate creating a menu with the word menu being rotated:

<div id="content">
Some content goes here in the middle…
<div id="menu">

Next, the CSS must be added to rotate the word menu so that it will appear vertically:

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

Summary of CSS transformations

With a bit more CSS, the following example can be produced without the need of a single issue:

Using some CSS3, rotating text or images or many other DOM elements is now extremely simple!

Tags: CSS | CSS | transform

My Books
ASP.NET MVC 5 With Bootstrap and Knockout.js
Knockout.js Building Dynamic Client-Side Applications
20 Recipes for Programming MVC 3
20 Recipes for Programming PhoneGap
Rapid Application Development with CakePHP