Problem with box shadows using pseudo elements

I have tried following multiple tutorials on creating curved box-shadows using pseudo elements, but for some reason it doesn’t display in any browser I try. I see it registering in Dev tools but no effect shows up. Can anyone tell me what Im doing wrong?

So far I tried this tool:
And this tutorial:

When I used the sitepoint one, the negative z-index makes it disappear completely, if I set it to 1 it displays on top.


I tried that tutorial several months ago and was never able to figure it out, either… same problem.

Based on your code (and assuming I kept my notes straight), this is what I did that worked for me.

add a “message-box” to your HTML as follows:

    <div class="box-shadow-preview">
        [color=blue]<div class="message-box"></div>[/color]

add to style.css

[color=blue].message-box {
    min-height:100px;    /* this gives the "message-box" a min-height; actual height is set by contents */

screen.css (line 1713)

.right_sidebar #main .content {
    overflow: hidden;    /* delete here or override in style.css as shown next */
    width: 630px;

add to style.css to override screen.css

[color=blue]#main .content {

style.css (line 71)

.box-shadow-preview {
    background-color: #FFFFFF;
    border-color: #DDDDDD;
    border-radius: 0;
    border-style: solid;
    border-width: 1px;
    [color=red]height: 200px;    /* delete me */[/color]
    position: relative;
    width: 500px;    /* this sets the width of the "shadow box" */

style.css (line 82)

.box-shadow-preview:before {
    bottom: 15px;
    box-shadow: 0 15px 10px #777777;
    content: " ";
    left: 10px;
    position: absolute;
    top: 160px;
    transform: rotate(-3deg);
    width: 50%;
    [color=red]z-index: -1;    /* delete me */[/color]

style.css (line 94)

.box-shadow-preview:after {
    bottom: 15px;
    box-shadow: 0 15px 10px #777777;
    content: " ";
    position: absolute;
    right: 10px;
    top: 160px;
    transform: rotate(3deg);
    width: 50%;
    [color=red]z-index: -1;    /* delete me */[/color]

I also suggest you use rgba colors for a nicer shadow effect:

box-shadow: 0 15px 10px rgba(119,119,119, 0.3);

Here’s an example of it in practice:

<!DOCTYPE html>
<html lang="en">


<meta charset="utf-8">

<style type="text/css" media="all">

body {background: #fafafa;}
pre {
	background: #fff;
	position: relative;
	border: 1px solid #ccc;
	padding: 7px;

code {
	display: block;
	background: #282C2C;
	color: #fff;
	font-family: monaco, monospace;
	font-size: 12px;
	line-height: 1.45;
	padding: 20px 15px;
	overflow: auto;

pre:before, pre:after {
  -webkit-box-shadow: 0 15px 10px rgba(0, 0, 0, 0.3);
  -moz-box-shadow: 0 15px 10px rgba(0, 0, 0, 0.3);
  box-shadow: 0 15px 10px rgba(0, 0, 0, 0.3);
  -moz-transform: rotate(-3deg);
  -webkit-transform: rotate(-3deg);
  -o-transform: rotate(-3deg);
  bottom: 15px;
  content: "";
  height: 20%;
  left: 10px;
  max-width: 300px;
  position: absolute;
  width: 50%;
  z-index: -1;

pre:after {
  -moz-transform: rotate(3deg);
  -webkit-transform: rotate(3deg);
  -o-transform: rotate(3deg);
  left: auto;
  right: 10px;

<p>Got the idea for this from</p>

<pre><code>body {
  color: #ccc;
  background: #cccfff;
  width: 500px;


I (=my Firebug ;)) was searching in an other direction, without adding new html-elements.

Step 1
The .box-shadow-preview is cut off at the bottom by the {overflow: hidden;} of the .content, so there is no space for shadow under it.
You can add:

.box-shadow-preview {
   margin-bottom: 30px;

Step 2
Then for the working of the z-index the box .box-shadow-preview itself and the :before and :after elements have to get a common parent with a z-index *). The parent is the .content, so there can be added:

.content {
   position: relative;
   z-index: 1;

(Every z-index has to be accompanied by an explicit position, here {position:relative;} is appropriate)

Step 3
No step 3: the rest can stay unchanged. :slight_smile:

Good luck!

*) This is often the solution for not working z-indexes: find the first common parent above them in the DOM-tree, and give that a z-index. Then there is a reference for both: no escape possible.

Ai, crosspost! :slight_smile:

Wow, thanks everybody! Great explanations, got it working!
@ralph definitely nicer shadows!

The [U][/U] are full of good recommendations, I see! :slight_smile:
Indeed, a dark grey can be softerized with a rgba opacity factor.
Or a straight lighter grey rgb color can be used. :wink:

Again crosspost! I’m as slow as a turtle. :wink: