Book Sale! Code WP2025 takes 20% OFF our Pro Plugins & Books »
Web Dev + WordPress + Security

CSS3 Tip: Removing Box Shadows

Adding box shadows is a great way to bring depth and focus to your design. You have probably seen this trick before:

.selector {
	-webkit-box-shadow: 0 3px 5px #333;
	-moz-box-shadow: 0 3px 5px #333;
	box-shadow: 0 3px 5px #333;
	}

Update! Browser support has improved. We now can just write box-shadow: none; to disable box shadow. Jump to the update for more information.

That CSS snippet will add a nice drop shadow to any matching selector. But what if you want to remove the box shadow from one or more of the matched elements? Easy, just declare none for any box-shadow property values:

.selector.noshadow {
	-webkit-box-shadow: none;
	-moz-box-shadow: none;
	box-shadow: none;
	}

Depending on the cascade, you may need to strengthen the .selector with greater specificity. Here we disable the box-shadow from all elements classed with .noshadow. So something like this:

<div class="selector">This box has a shadow</div>
<div class="selector noshadow">This box has no shadow</div>
<div class="selector">This box has a shadow</div>

Update: prefix properties no longer needed

Browser support for box-shadow has matured. The browser-specific properties prefixed with -webkit- and -moz- no longer are required. Now we can add and remove box shadows like so:

.selector {
	box-shadow: 0 3px 5px #333; /* add box shadow */
	}
.selector {
	box-shadow: none; /* remove box shadow */
	}

Cheers people.

About the Author
Jeff Starr = Creative thinker. Passionate about free and open Web.
.htaccess made easy: Improve site performance and security.
Welcome
Perishable Press is operated by Jeff Starr, a professional web developer and book author with two decades of experience. Here you will find posts about web development, WordPress, security, and more »
Wizard’s SQL for WordPress: Over 300+ recipes! Check the Demo »
Thoughts
Arc browser looked good but lost me at “account required”. No thank you.
Finishing up the pro version of Head Meta Data plugin, launch planned this month.
Finally finished my ultimate block list to stop AI bots :) Blocks over 100 AI bots!
After 10 years working late at night, my schedule has changed. I am now a “morning person”, starting my day at 6am or earlier.
Nice update for Wutsearch search engine launchpad. Now with 19 engines including Luxxle AI-powered search.
New version of 8G Firewall (v1.4) now available for download :)
Wishing everyone a prosperous and bright New Year!
Newsletter
Get news, updates, deals & tips via email.
Email kept private. Easy unsubscribe anytime.