views:

1819

answers:

6

Well I guess this is a two part question.

Firstly how can I make an image have partial transparency (I think you can do this with PNGs but don't know how -- I have photoshop just need instructions?)

Secondly how do I use that image in a layout using CSS? I think I need some kind of "PNG Hack"

+1  A: 

The easy option which probably won't work for you:

Webkit browsers (Safari, Chrome) can use the -webkit-box-shadow CSS3 property. Firefox and IE (of course) don't support this (or have a vendor-specific equivalent) yet.

The other options you're left with are numerous, and widely covered on the Internet (since every man and his dog want to use drop shadows)

http://www.google.com/search?q=how+to+make+a+drop+shadow

Just one thing I'd add: before you go messing with transparent PNG hacks, you should consider how many of your users are still on IE6, and how important it is to you to be making your site pretty for someone who hasn't upgraded in 8 years.

nickf
Guess you didn't read the body of my question. I wasn't looking for a CSS3 answer that 3% of people will see
Andrew G. Johnson
No, I did - that's why I said that the pure CSS solution probably wouldn't work, but it's still an option for 3% of users. Who knows: that could still be useful to someone.
nickf
Firefox 3 will support box-shadow and text-shadow properties. The beta I am using right now does. It pretty slick.
Squeegy
I read the question and it never said anything about CSS3 or target browsers. This is a valid answer/solution in some circumstances but comes with a clearly stated caveat. +1 because the answer is not technically wrong.
Andy Ford
+2  A: 
  1. Create a new photoshop document
  2. Add new layers and draw on them
  3. Delete the layer named Background
  4. File > Save for Web
  5. Choose a 24 bit PNG format.

Getting it to work well in IE6 is going to be the issue. You should use a separate stylesheet that only ie6 loads via conditional comments that loads the backgorund image like this:

filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src="my_trans_image.png", sizingMethod="crop");

And in your standard style sheet use it like any other image:

background-image: url(/path/to/my_trans_image.png);

Load a stylesheet with IE6 specific rules in it like so:

<!--[if lt IE 7]>
<link rel="stylesheet" href="/css/ie6.css" type="text/css" charset="utf-8" />
<![endif]-->

This will only load in IE and if the version is less than 7.

Final note: IE6 is rapidly fading out. If you dont need to support IE6 then setting the PNG as a background image in plain old CSS will work in all modern browsers without any real problems.

Squeegy
umm - a 24 bit PNG will not have an alpha channel, that is, no partial transparency
DrJokepu
That's what photoshop calls it. It its really a 24 bit PNG with transparency, technically being 32 bit. http://beautifulpixel.com/assets/photoshop_png_saving-20090205-143342.png
Squeegy
Really? That's really confusing.
DrJokepu
I've never arsed myself to rig up a png fix for IE6, but I think that the IE6 CSS definitions will require that your block element has a fixed height and width for AlphaImageLoader() to work.
kRON
@DrJokepu — "Really confusing" is fairly typical of Photoshop, in my experience.
Ben Blank
A: 

Well, that's the idea - you need to create transparent PNGs. I usually use Paint.NET for these sort of stuff but if you feel more comfortable using Photoshop, go ahead. All you need is to have a transparent background on your image and then put some semitransparent dark pixels on that would become the shadow.

You can use images with CSS by the background-image property. That is:

#myDiv
{
    background-image: url('myimage.png');
}

IE6 doesn't support PNG transparency out of the box - google for IE6 PNG hack or just search this site. Also, be warned that even though IE7 supports PNG transparency, it is awfully slow so it's next to unusable for advanced effects like shadows. You might want to have some more basic fallback style for Internet Explorer.

DrJokepu
+1  A: 

To address your second question: If you don't mind using a little JavaScript, you can use a png fix JavaScript file to automagically apply the IE-specific filter to your images.

Zack Mulgrew
A: 

Make sure your glow/shadow uses a Blend Mode of "Normal". Other blend modes such as Multiply or Screen are really awesome inside Photoshop, but won't look as expected on the web.

If you need to support IE6, you'll need some sort of PNG fix solution. This post lists several: http://stackoverflow.com/questions/86545/is-there-a-javascript-png-fix-for-ie6-that-allows-css-background-positioning/480085

My personal favorite is : http://www.dillerdesign.com/experiment/DD_belatedPNG/

Andy Ford
A: 

The typical IE PNG fix actually causes IE to crash under certain conditions. (google it). Unless the user has tweaked a registry setting (hah). Unless you want an implicit fuck you to some of your IE6 users, try using VML for transparent PNG images instead. the raphael.js lib is a nice way to achieve that.

http://raphaeljs.com/

Breton