• 0

Convincing shadows, using CSS!


Question

I stumbled onto this just a few minutes ago, and I figured I'd share it with you guys. This very well might have been used before, but it's new to me.

To make a nice top-banner for your website and add a very nice looking 3px drop shadow to it. First, put the following divs in your HTML page (the first thing after your body tag)

<div id="topbanner"></div>
<div id="shadow"></div>
<div id="bottombanner"></div>

Then, the CSS for these banners will look like this:

#topbanner {
	background-color: #003399; 
	margin: 0px;
	padding: 0px;
	height: 30px;
	width: 100%;
}
#shadow {
	background-color: #646b9d; //Middle stripe of shadow
	margin: 0px;
	padding: 0px;
	height: 3px;
	width: 100%;
	border-top: 1px solid #393e5a; //Darkest stripe of shadow
	border-bottom: 1px solid #818bcb; //Lightest stripe of shadow

/* The following code ensures that the middle stripe of the shadow will only be 1px tall in all browsers */
	voice-family: "\"}\"";
	voice-family: inherit;
	height: 1px;
}
body>#shadow {
	height: 1px;
}
#bottombanner {
	background-color: #8f9ae1; //Color of bottom banner
	margin: 0px;
	padding: 0px;
	height: 10px;
	width: 100%;
}

Also, make sure your <body> tag has the 'margin: 0px' and 'padding: 0px' styles applied to it.

Here's what it'll look like once it's done: CSS Shadow

All I did was make two boxes of the color I wanted in Photoshop and add a drop shadow (distance: 1, size: 3) to the top box. then i used the dropper to get the three colors that made up the shadow and used them in my CSS. So this can be done with any two colors, as long as you have an image editing program so you can get the colors right.

If you don't want a bottom banner, and just want a drop shadow against a white bg, the three colors are:

dark > #666666

middle > #B2B2B2

light > #E6E6E6

Ok, I'm done now...It's just a nice subtle effect that can add a bit o' depth to your page without adding any weight.

Link to comment
Share on other sites

Recommended Posts

  • 0
Looks the same in IE

MS Should make IE optional. They can install it, but I'm sure that if they do not include any shortcuts to it, 90% of the people that would otherwise use it would use another browser. Seriously :D

Link to comment
Share on other sites

  • 0

dammit IE...

adding the XHTML doctype puts IE into 'standards' mode, but it still won't render this right.

what a pain-in-the-ass.

well, i thought it was a good idea. :(

Link to comment
Share on other sites

  • 0

well i'm gonna keep trying to get it to work. i really want to use this for my site, so i hope i can nail down the problem.

Link to comment
Share on other sites

  • 0

@Angel: what are you referring to as an 'IE-only extension'??

@anyone with IE6: I added a containing div whose height is 43px (30+3+10) so that might keep the shadow div from expanding.

Anyone wanna let me know (don't forget to refresh to make sure you're looking at the new one...

Link to comment
Share on other sites

  • 0

alright...so let's see.

well from your screenshot, dazzla, not only is the shadow bar too big, but the bottom banner is too tall as well.

perhaps IE just can't render divs under a certain height? that would be just plain stupid...because even IE5.2/Mac does just fine with this.

time to scrap the project?

Link to comment
Share on other sites

  • 0

Don't scrap the project, I have an idea for you. Make a section on your site dedicated to browser comparison. Be sure to include some transparent PNGs in there too. Also, give them a link to firebird! Everyone will be happy! :p

Link to comment
Share on other sites

  • 0

don't scrap it... it looks awesome on moz/firebird... i'm just starting to learn stylesheets etc and this is a good learning exercise for me... :)

Edited by rezza
Link to comment
Share on other sites

  • 0
Don't scrap the project, I have an idea for you. Make a section on your site dedicated to browser comparison. Be sure to include some transparent PNGs in there too. Also, give them a link to firebird! Everyone will be happy! :p

well i am going to have a tutorial/CSS section on my site.

I've done a lot of searching to find info on CSS and i thought I'd compile it all together.

a section on browser compatibility isn't such a bad idea actually...just to show people how different browsers render different styles...and of course provide dl links to all the 'good', standards-compliant browsers. ;)

Link to comment
Share on other sites

  • 0

Ok, well i found a stupid error in my CSS, so i fixed it and uploaded it.

if someone who has IE6 would be so kind as to check it out (it should have text on the page now, too)

thanks.

Link to comment
Share on other sites

  • 0

Here's a cheap hack (and messy) attempt on cloning his CSS method.

&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Sloppy Tables Example&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;/head&gt;

&lt;body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"&gt;
&lt;table width="100%" border="0" cellspacing="0" cellpadding="0"&gt;
  &lt;tr&gt; 
    &lt;td height="36" align="center" valign="middle" bgcolor="#003399"&gt; 
      &lt;p&gt;&lt;font color="#FFFFFF" size="3" face="Verdana, Arial, Helvetica, sans-serif"&gt;space.for.vorte[x]&lt;/font&gt;&lt;/p&gt;&lt;/td&gt;
  &lt;/tr&gt;
&lt;/table&gt;
&lt;table width="100%" border="0" cellspacing="0" cellpadding="0"&gt;
  &lt;tr&gt; 
    &lt;td height="2" bgcolor="#646B9D"&gt;&lt;/td&gt;
  &lt;/tr&gt;
&lt;/table&gt;
&lt;table width="100%" border="0" cellspacing="0" cellpadding="0"&gt;
  &lt;tr&gt; 
    &lt;td bgcolor="#8F9AE1"&gt;&lt;/td&gt;
  &lt;/tr&gt;
&lt;/table&gt;
&lt;p&gt;&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.