Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS3: Cube with shadow

I think images speak louder than words in this case.

I want to get this effect:

enter image description here

But the best I can do with CSS3 is this:

enter image description here

And the code for this is absolutely terrible:

box-shadow: 1px 1px hsl(0, 0%, 27%),
            2px 2px hsl(0, 0%, 27%),
            3px 3px hsl(0, 0%, 27%),
            4px 4px hsl(0, 0%, 27%),
            5px 5px hsl(0, 0%, 27%),
            6px 6px hsl(0, 0%, 27%),
            7px 7px hsl(0, 0%, 27%),
            8px 8px hsl(0, 0%, 27%),
            ...

Is there any way that I can create an effect like this with pure CSS3? I don't mind having it be 3D, but isometric would be preferred.

I don't need to place content onto the sides of the box, just onto the front face, so I'm working with just a single <div> element.

Here's what I have so far: http://jsfiddle.net/X7xSf/3/

Any help would be appreciated!

like image 788
Blender Avatar asked Nov 01 '11 18:11

Blender


People also ask

Can we apply transform property to box shadow?

Using transforms on the box-shadow (& transform ) property, we can create the illusion of an element moving closer or further away from the user.

How does CSS box shadow work?

The box-shadow CSS property adds shadow effects around an element's frame. You can set multiple effects separated by commas. A box shadow is described by X and Y offsets relative to the element, blur and spread radius, and color.


1 Answers

I'd use some skew transforms on some CSS generated elements... Take a look at this:

http://jsfiddle.net/X7xSf/12/

If I wanted to use this in production, I'd probably identify which browsers support before and after, but not transforms (only IE8), then use Paul Irish's method from 2008 (http://paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/) to turn this off for IE8.

like image 177
Rich Bradshaw Avatar answered Oct 03 '22 08:10

Rich Bradshaw