This is the blog of web developer and designer Andy Walpole.

Create and do what is new, through and through.


Drupal Association membership badge

A Blog in Suburban Glory: Web Design Ideas and Inspiration

Using CSS3 box-shadow to create a glow effect

Andy Walpole || Category: CSS || Fri 29th Jan 2010

This is a technique I discovered by accident when creating the Drupal Sunset theme.

The purpose of the box-shadow property is self-explanatory – it creates a shadow around an element.

I've used box-shadow quite a few times in the past and it is an impressive addition to the CSS stable. I've tried to find an alternative for IE - using either filters or JavaScript - but I haven't found one that works properly yet.

Here's an example of the code:

-webkit-box-shadow:5px 5px 5px #999999; 
-moz-box-shadow: 5px 5px 5px #999999; 
box-shadow:5px 5px 5px #999999; 

The three measurements in order are the horizontal offset, the vertical offset and the blur radius.

Here's how this would look in Firefox, Chrome or Safari – the only browsers to read this CSS3 feature so far:

Box shadow number one

It produces an attractive grey border.

Lets change the code:

-webkit-box-shadow:0 0 15px #ffffff; 
-moz-box-shadow: 0 0 15px #ffffff; 
box-shadow:0 0 15px #ffffff; 

Reducing the horizontal and vertical offset to zero, increasing the blur radius and changing the shadow colour to white so that there is a more striking contrast between the foreground and background creates this:

Box shadow number two

As you can see it creates quite a pleasant glow and it degrades gracefully as the browsers that don't recognise box-shadow merely see a border.

Comments

chodorowicz || Sun 14th Mar 2010

nice trick! thanks

You can add comments below.
Auto-paragraphing is enabled. Double newlines will be converted to paragraphs.

Allowed tags: a, abbr, acronym, b, blockquote, caption, cite, code, dd, del, dfn, div, dl, dt, em, i, ins, kbd, li, ol, p, pre, s, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, var.

If you wish add code examples then please do so between the following tags:

<pre><![CDATA[
Place code here
]]></pre>







+ + + + + +