Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

3D Box Shadow effect

Tags:

css

css-shapes

So I know how to do a basic box shadow with CSS3. You can see that in the top of the graphic below.

The effect I'm trying to achieve is a 3D box shadow, as shown in the bottom of the graphic below.

Any ideas on how to do this with CSS3 box shadows?

3D box shadow effect

like image 368
Corey Avatar asked Dec 04 '14 16:12

Corey


2 Answers

you can use pseudo element for as shadow

div {
  background: black;
  height: 100px;
  width: 100px;
  position: relative;
}
div:after,
div:before {
  content: '';
  background: grey;
  position: absolute;
}
div:after {
  width: 100%;
  height: 20px;
  left: 10px;
  bottom: 0;
  transform: translatey(100%) skewx(45deg);
}
div:before {
  width: 20px;
  height: 100%;
  right: 0;
  transform: translatex(100%) skewy(45deg);
  top: 10px;
}
<div></div>
like image 56
Vitorino fernandes Avatar answered Oct 20 '22 02:10

Vitorino fernandes


Unfortunately box shadows are effectively just flat layers. However you can apply multiple box shadows to create this effect.

.box-shadow-3d{
    box-shadow: 1px 1px 0px #999,
                2px 2px 0px #999,
                3px 3px 0px #999,
                4px 4px 0px #999,
                5px 5px 0px #999,
                6px 6px 0px #999;
}
like image 20
BurpmanJunior Avatar answered Oct 20 '22 01:10

BurpmanJunior