views:

44

answers:

3

I have this code to cast a shadow on imagese:

.shadow{
box-shadow: -2px 2px 4px #666;
-webkit-box-shadow: -2px 2px 4px #666;
-moz-box-shadow: -2px 2px 4px #666;
filter: progid:DXImageTransform.Microsoft.dropShadow(color=#666, offX=-2, offY=2, positive=true);
}

This works in FF, Opera, Safari, Chrome but not in IE6 (haven't tested any other IE version yet)

Thanks

UPDATE:

 <img src="......" class="shadow">

No width or height specified...

The problem is that the shadow is crisp and completely black, instead of fading like a shadow should, and like it does in FF for example. Hard to describe... The shadow is there, but it isn't faded, its like a black box behind the image.

A: 

Using a colon in a CSS property is definitely incorrect. The correct way to address those DX filters seems to be an underscore:

filter: progid_DXImageTransform.Microsoft.dropShadow(color=#666, offX=-2, offY=2, positive=true);
Pekka
in microsoft's examples they use colon http://msdn.microsoft.com/en-us/library/ms532985%28VS.85%29.aspx
Sotiris
@Sotiris funny, I have an example where they use underscores: http://msdn.microsoft.com/en-us/library/ms532969(VS.85).aspx but colons are definitely in the majority, it seems to work.
Pekka
I'd never seen the underscore notation before. Using a colon is indeed incorrect, but that's in fact what it was: http://blogs.msdn.com/b/ie/archive/2009/02/19/the-css-corner-using-filters-in-ie8.aspx And I've just tested it with an underscore and that does not, in fact, work, so that just looks like an MSDN error.
mercator
+1  A: 

The element needs to have layout (from MSDN):

Almost any object can have filters applied to it. However, the object that the filter is applied to must have layout before the filter effect will display. Put simply, having layout means that an object has a defined height and width. Some objects, like form controls, have layout by default. All other filterable objects gain layout by setting the height or width property, setting the position property to absolute, setting the writingMode property to tb-rl, or setting the contentEditable property to true.

Also see On having layout for more details.

Note also that that filter syntax will only work in IE6 and IE7. IE8 needs the -ms-filter property instead, and its value should be in quotes.

In short, to make it work in IE6, add zoom: 1, and to make it work in IE8 too, add an -ms-filter property (before the filter property!):

.shadow {
    box-shadow: -2px 2px 4px #666;
    -webkit-box-shadow: -2px 2px 4px #666;
    -moz-box-shadow: -2px 2px 4px #666;
    -ms-filter: "progid:DXImageTransform.Microsoft.dropShadow(color=#666, offX=-2, offY=2, positive=true)";
    filter: progid:DXImageTransform.Microsoft.dropShadow(color=#666, offX=-2, offY=2, positive=true);
    zoom: 1;
}
mercator
What exactly do you mean by all this... Care to write the small code as it should be then? Check my update for the element it is applied to...
Camran
@Camran see his edit: Try adding `zoom: 1`. I doubt this is it, though, because an image should already have Layout by default.
Pekka
@Pekka, indeed. If it had been a div this would've done it, but judging by Camran's update there is no problem to begin with. He's already getting a shadow, just not a blurry one, which IE doesn't support.
mercator
This makes no difference. But thanks anyways... A blurry shadow is impossible in IE6 this way? Does no IE support blurry shadows?
Camran
@Camran: Nope. IE doesn't support CSS3, so don't expect it to behave like it does. This is as good as it's going to get with IE's _filters_. You could try the `Glow` filter (http://msdn.microsoft.com/en-us/library/ms532995(VS.85).aspx) instead of the `DropShadow` filter. It's not what you want either, but maybe it'll do.
mercator
Omg, this is going to be a big problem... IE is worthless
Camran
@Camran, if you desperately need it, you could add an empty, absolutely positioned div *before* the image, with the same dimensions as the image and a gray background, and apply the Blur filter to *that* instead.
mercator
A: 

use something like this and change according to your needs:

.shadow{
box-shadow: -2px 2px 4px #666;
-webkit-box-shadow: -2px 2px 4px #666;
-moz-box-shadow: -2px 2px 4px #666;
cursor:hand;
height:160px; 
padding:10px;
filter:progid:DXImageTransform.Microsoft.dropshadow(OffX=-2, OffY=2,  Color=#666, Positive='true');
}

it works ie7 & 8 (I don't have 6).

Sotiris
Does it work with blurry shadow in IE7 and 8?
Camran
if you wish blur you can add this `filter:progid:DXImageTransform.Microsoft.Blur(PixelRadius='5', MakeShadow='true', ShadowOpacity='0.40');`
Sotiris
@Sotiris: You mean add that filter right below the other filter?
Camran
test it with and without the other filter, and keep what you like
Sotiris