I have a PNG image, that has free form (non square).
I need to apply drop-shadow effect to this image.
The standard approach ...
-o-box-shadow: 12px 12px 29px #555;
-icab-box-shadow: 12px 12px 29px #555;
-khtml-box-shadow: 12px 12px 29px #555;
-moz-box-shadow: 12px 12px 29px #555;
-webkit-box-shadow: 12px 12px 29px #555;
box-shadow: 12px 12px 29px #555;
... displays shadows for this image, like it is a square. So, I see my image and square shadow, that doesn't follows the form of object, displayed in image.
Is there any way to do it properly?
Maybe you are in search of this. http://lineandpixel.com/blog/png-shadow
Add border with radius in you class if its a block. because by default shadow will apply on block border, even if your image have rounded corner.
border-radius: 4px;
change its border radius according to your you image corner. Hope this help.
You can't do this reliably across all browsers. Microsoft no longer supports DX filters as of IE10+, so none of the solutions here work fully:
https://msdn.microsoft.com/en-us/library/hh801215(v=vs.85).aspx
The only property that works reliably across all browsers is
box-shadow
, and this just puts the border on your element (e.g. a div), resulting in a square border:box-shadow: horizontalOffset verticalOffset blurDistance spreadDistance color inset;
e.g.
If you happen to have an image that is 'square' but with uniform rounded corners, the drop shadow works with
border-radius
, so you could always emulate the rounded corners of your image in your div.Here's the Microsoft documentation for
box-shadow
:https://msdn.microsoft.com/en-us/library/gg589484(v=vs.85).aspx
This won't be possible with css - an image is a square, and so the shadow would be the shadow of a square. The easiest way would be to use photoshop/gimp or any other image editor to apply the shadow like core draw.
A little late to the party, but yes, it is totally possible to create "true" dynamic drop shadows around alpha masked PNGs, using a combination of dropshadow-filter (for Webkit), SVG (for Firefox) and DX filters for IE.
Some comparisons between true drop-shadow and box-shadow and an article on the technique I've just described.
I hope this helps!
Just add this:
example: