A Web Design Community curated by Chris Coyier

A little dab'll do ya

Code Snippets

Home » Code Snippets » CSS » Top Shadow Submit one!

Top Shadow

Shadow along the top edge of the website, like this:

body:before {
          content: "";
          position: fixed;
          top: -10px;
          left: 0;
          width: 100%;
          height: 10px;

          -webkit-box-shadow: 0px 0px 10px rgba(0,0,0,.8);
              -moz-box-shadow: 0px 0px 10px rgba(0,0,0,.8);
                         box-shadow: 0px 0px 10px rgba(0,0,0,.8);

          z-index: 100;
}

Reference URL

Subscribe to The Thread

  1. myst says:

    yeah, but browser slow down if use position:fixed on site with content. maybe you know reason?

    • I did some testing with that and didn’t seem to find any slowdown. Do you have a test page showing the problem?

    • myst says:

      No, i try add code in my site with other content & get slowdown, i think code with position: fixed; work fine if is demo page with no-content )) in real sites it slow.

    • With content, with scrolling: http://jsbin.com/ejora3

      No slowdown.

      What matters is doing tests. Make a test page with different content that DOES slow it down, and we can troubleshoot from there.

      “Reduced Test Cases” http://css-tricks.com/reduced-test-cases/

    • myst says:

      Go to my home page please, you see. With other skins for cms it works fine.

    • Scrolls fine for me. If it doesn’t for you, that means it’s either 1) the browser/version 2) the platform/version 3) your computer in general and all of that in conjunction with the HTML/CSS/JavaScript on your page. That’s the point of the reduced test case. Add the top shadow, experience slowness, remove things from the page slowly until it fixes the problem, then that was the thing that was causing the problem. Or do it in reverse, add the top shadow, then add things back into an otherwise empty page until it breaks. The last thing you added is the problem.

    • myst says:

      I use different browsers for testing on machine with 1GB of memory & Win-x64. Opera -11 (very-very slow), Safary (no smooth scrolling) =( Thanks for any way. Thanks anyway. I’ll try to find the cause.

    • myst says:

      I’ve found. lot of text-shadow on my site for any text. Sorry, it is my fault

  2. It works damn fine at my side should i use it or not

  3. If I wanted to do the same type of shadow but coming up from a full-width , what would the change be?

  4. Is there an easy way to accomplish on the bottom side as well? Love the effect.

    • DogsGhost says:

      If you want it at the bottom of the page -

      body:after {
      content: “”;
      position: fixed;
      bottom: -10px;
      left: 0;
      width: 100%;
      height: 10px;

      -webkit-box-shadow: 0px 0px 10px rgba(0,0,0,.8);
      -moz-box-shadow: 0px 0px 10px rgba(0,0,0,.8);
      box-shadow: 0px 0px 10px rgba(0,0,0,.8);

      z-index: 100;
      }

  5. ConnyLo says:

    Hey, thank you very much for that trick! I love it (and use it until now).

  6. e11world says:

    Nicely done! I like this.

  7. Otavio says:

    This is a very nice resource, i will use it as soon :)

  8. Great work,

    thx it works perfectly.

    wise

  9. Paul says:

    Hi Chris

    Great job ( as usual.)

    One small but important question though.

    When browsers ( that support box-shadow property ) render the shadow, it automatically draw the shadow pixel by pixel and then repeat it, and the same in the case of text-shadow too.

    Am I correct ?

    If so, in the exact same setting, a page with many elements styled with shadow-thingy will render slower than a page without those shadows.

    The time taken to render those shadow will not be that much different, unless it gets to a certain point ( which vary by RAM/ browsers and a few others )

    Am I correct ?

  10. I would even to this to make the left and right edges of the shadow go all the way to the end rather than drop off slightly.

    body:before {
    content: "";
    position: fixed;
    top: -10px;
    left: -10px;
    width: 110%;
    height: 10px;

    -webkit-box-shadow: 0px 0px 10px rgba(0,0,0,.8);
    -moz-box-shadow: 0px 0px 10px rgba(0,0,0,.8);
    box-shadow: 0px 0px 10px rgba(0,0,0,.8);

    z-index: 100;
    }

    Not totally noticeable but just one of those pixel perfect things.

  11. Pablinho says:

    I had seen this here: http://playground.genelocklin.com/depth/

    And im still unsure as to how they make it work on IE7 – IE8, any ideas ?

It's Your Turn

At this moment, you have an awesome opportunity* to be the person your mother always wanted you to be: kind, helpful, and smart. Do that, and we'll give you a big ol' gold star for the day (literally).

Posting tips:
  • You can use basic HTML
  • When posting code, please turn all
    < characters into &lt;
  • If the code is multi-line, use
    <pre><code></code></pre>
Thank you,
--- The Management ---