Isometric 3D Effect with CSS3 Transformations
I recently had the opportunity to make use of CSS3 transformations to achieve a 3D effect in a practical application.
If you’re a web developer reading this, you know that something like this doesn’t happen every day, and is therefore very exciting!
The main requirement for the project was to display a 3D isometric floorplan of the Convergence Centre at Western University in London Ontario, with tweeps showing up in the room they are tweeting from.

Each room is a <div class=”users”> that can contain <div class=”avatar”> as many times as needed. Transparent GIF’s are used as background images for the character’s body, head, torso and legs.
<div id="bar" class="users"> <div class="avatar"> <div class="head"></div> <div class="torso"></div> <div class="legs"></div> </div> <div class="avatar"> <div class="head"></div> <div class="torso"></div> <div class="legs"></div> </div> </div> <div id="maple" class="users"> <div class="avatar"> <div class="head"></div> <div class="torso"></div> <div class="legs"></div> </div> </div>
For development purposes, we put a thick red border around the rooms.
As we add more avatars to a room, we’ll adjust their margins so that characters squeeze closer together and the room will not overflow.
Avatars are floated right so they stack nicely – closer ones will overlap farther avatars.

.users {
border: 4px dashed red;
position: absolute;
}
.users .avatar {
height: 44px;
width: 33px;
float: right;
margin: 17px;
position: relative;
}
.head, .torso, .legs {
position: absolute;
top: 0;
left: 0;
height: 44px;
width: 33px;
}
Adding CSS3 transformations, we can skew the room divs to match the shape of the rooms in the background image.
The side-effect of this is that the avatars inside will also be skewed.
The CSS below will affect Mozilla and Webkit-based browsers only.

.users {
border: 4px dashed red;
position: absolute;
-moz-transform: skewX(45deg) skewY(-12deg);
-webkit-transform: skewX(45deg) skewY(-12deg);
}
Now we have to put an opposite skew on the avatars to cancel out the room skew.
.users .avatar {
-moz-transform: skewX(-50deg) skewY(12deg) scaleX(1.2);
-webkit-transform: skewX(-50deg) skewY(12deg) scaleX(1.2);
}

All that’s left is to remove the red border around the rooms!
If you have any questions or comments about using CSS3 to achieve a 3D effect, or if you want to show off your own 3D CSS3 project, we’d love to hear from you!


November 6th, 2010 at 12:55 am
Currently working on my own isometric game engine built in javascript and was looking for information about CSS transforms. This post struck a cord with me because I’m originally from London, Ontario.
Anyways, I’m using a different sort of CSS transform that involves “rotate” as well. But my problem is that my sprites, which are transformed because of their parent tile, as very blurry and distorted.
If you’re bored take a look at my development branch on Github. https://github.com/Emerson/MapTime/tree/development
It’s barley functional, but already has some basic pathfinding. Follow these steps to see an example:
1. Click any time on the map to add “impassable terrain.”
2. Click “add unit” from the main top menu.
3. Click on the unit to select it.
4. Move the cursor around the map to see instant pathfinding updates.
If you’re bored feel free to fork the project and started contributing.
November 6th, 2010 at 12:56 am
Opps, lots of spelling errors… wishing there was an “edit” button now.
November 8th, 2010 at 2:14 pm
Hi Emerson,
I took at look at your game, it looks promising! The pathfinding is really cool.
I think I ran into the blurry/distorted sprites issue with “rotate”, that’s why I ended up using skews. Give it a try and let me know if it helps. If you don’t already use it, Firebug is really nice for trying out things like that.
I’m definitely going to keep an eye on your project
Cheers,
Gavin
December 2nd, 2010 at 3:35 pm
hey Gavin,
this is a pretty sweet trick – definitely going to try it out on some of my CSS3 projects.
One question though – how did you figure out the opposite skew for the avatars to be
skewX(-50deg) skewY(12deg) scaleX(1.2)?
I ran into this problem when trying to reverse 3D rotations as well (rotateX, rotateZ, etc.) where doing the opposite transform doesn’t fix it.
December 9th, 2010 at 11:45 am
Hi Rob,
Truthfully, I just used Firebug and played with combinations of the transforms and numbers until it looked right.
You’ll notice that the end result avatars are a little taller and skinnier than the originals. I was OK with that, but it won’t be right in some circumstances. I’d love to see some of the stuff you’re working on!
Cheers,
gav