Home arrow JavaScript arrow Page 3 - Building Dynamic Shadows with JavaScript and CSS
JAVASCRIPT

Building Dynamic Shadows with JavaScript and CSS


Do you like the three-dimensional effects that dynamic shadows can add to your web site? In this three-part series, you'll learn how to create this effect with JavaScript and CSS. This first part shows you how to implement some basic CSS approaches to build a few primitive shadowed web page elements.

Author Info:
By: Alejandro Gervasio
Rating: 5 stars5 stars5 stars5 stars5 stars / 1
June 29, 2009
TABLE OF CONTENTS:
  1. · Building Dynamic Shadows with JavaScript and CSS
  2. · Dropping shadows with CSS: building simple background images
  3. · Using CSS borders for shadowed web page elements
  4. · Building shadowed elements with liquid dimensions

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Building Dynamic Shadows with JavaScript and CSS - Using CSS borders for shadowed web page elements
(Page 3 of 4 )

As I mentioned in the section you just read, it's possible to build pretty realistic shadows by using the "border" CSS property. This property can be easily incorporated into any element of a web page, since it's generally well supported by most modern browsers.

This basic shadowing technique is based on specifying an "outset" value for the border style of the targeted web page element. The (X)HTML file below demonstrates a simple implementation of this technique, so take a look at it, please:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Example of shadowed DIV using the outset border property (fixed size)</title>

<style type="text/css">

body{

padding: 0;

margin: 0;

background: #fff;

}

h1{

text-align: center;

margin: 0;

font: bold 16pt Arial, Helvetica, sans-serif;

color: #000;

}

p{

font: normal 10pt Arial, Helvetica, sans-serif;

color: #000;

}

#container{

width: 350px;

padding: 10px;

margin-left: auto;

margin-right: auto;

background: #ccc;

border: 3px outset #fff;

}

</style>

</head>

<body>

<h1>Example of shadowed DIV using the outset border property</h1>

<div id="container">

<p>Content for DIV element goes here. Content for DIV element goes here. Content for DIV element goes here. Content for DIV element goes here. Content for DIV element goes here. Content for DIV element goes here. Content for DIV element goes here. Content for DIV element goes here. Content for DIV element goes here. Content for DIV element goes here. Content for DIV element goes here. Content for DIV element goes here. Content for DIV element goes here. Content for DIV element goes here. Content for DIV element goes here. Content for DIV element goes here. Content for DIV element goes here. Content for DIV element goes here. Content for DIV element goes here. Content for DIV element goes here. Content for DIV element goes here. Content for DIV element goes here. Content for DIV element goes here. Content for DIV element goes here. Content for DIV element goes here. Content for DIV element goes here.</p>

</div>

</body>

</html>

In this particular case, the above (X)HTML file uses a few simple CSS styles to add a raw shadow to one DIV identified as "container," via the proper manipulation of its "border" property. This is only a simple approach for adding basic shadows to certain elements of a web document; it uses a target DIV whose respective height has been specified in pixels.

The final result of using this approach can be seen in the sample image below:



Not too bad, right? As you saw in the previous example, by tweaking the border style property of a selected DIV, it's feasible to incorporate a shadow effect, even though it looks pretty primitive. However, this CSS technique has been used with elements that have a fixed width, so in the section to come I'm going to explain how to add this shadow effect to DIVs that have liquid dimensions.

To see how this will be done, go ahead and read the next few lines. They're just one click away.


blog comments powered by Disqus
JAVASCRIPT ARTICLES

- More Top jQuery Tutorials for Beginners
- More Top jQuery Plugins for Menus
- Top jQuery Tutorials for Beginners
- New UI Framework and SDK for JavaScript Rele...
- JavaScript OpenPGP Tool, Node.js 0.6.3 Avail...
- Yahoo Releases Cocktails Language and Develo...
- Customizing jQuery Slideshows: Dynamic Contr...
- Customizing jQuery Slideshows: the animate()...
- Customizing jQuery Slideshows: slideUp() and...
- Customizing jQuery Slideshows: hide() and sh...
- Web Workers: Performing Calculations in Para...
- More Top JavaScript Frameworks and Libraries
- More Dynamic jQuery Styling Techniques
- The Top JavaScript Libraries
- The Top JavaScript Frameworks

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 1 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials