I've always been using CSS box-shadows since, but now I have an image with rounded corners and wanted to give it a rounded shadow. So I tried using filter: drop-shadow, but unfortunately it looks different from box-shadow. In my opinion, they should look the same, am I doing something wrong?
td {
padding: .5em 3em;
}
.box-shadow img {
box-shadow: 0 0 10px rgba(0, 0, 0, 0.7);
}
.drop-shadow img {
filter: drop-shadow(0 0 10px rgba(0, 0, 0, 0.7));
}
<table>
<tr>
<th>box shadow</th><th>drop shadow</th>
</tr>
<tr>
<td class="box-shadow">
<img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97150&w=150&h=150" alt="" />
</td>
<td class="drop-shadow">
<img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97150&w=150&h=150" alt="" />
</td>
</tr>
</table>
Is the appearance of these shadows defined in any spec, or do browsers just what they think they should do? Why do those look different?
Chrome/OS X:
Firefox/OS X:
The values for text-shadow are the same as box-shadow and in the same order. The only difference is that text-shadow has no spread value and no inset keyword.
What is a drop shadow? Drop shadows give the impression that a layer in your Photoshop project is hovering and casting a shadow onto the background layer beneath it. You can apply a drop shadow to any type of Photoshop layer to help give the impression that your image exists in 3D space.
The box-shadow property enables you to cast a drop shadow from the frame of almost any element. If a border-radius is specified on the element with a box shadow, the box shadow takes on the same rounded corners.
A drop shadow is a visual effect in graphic design where one draws a copy of an object in black or gray in a slightly different position to look like the object's shadow. This effect gives the effect of elevating the object above those behind it.
I believe this is a bug. The W3C specification for CSS filters states that "values are interpreted as for box-shadow [CSS3BG]." Therefore, similar results should be expected from the two properties.
I achieved a similar issue, as seen here:
#box1, #box2 {
position: absolute;
top: 10px;
width: 100px;
height: 100px;
background: red;
}
#box1 { /* Using drop shadow, should appear identical to box shadow */
left: 10px;
filter: drop-shadow(0 5px 10px black)
}
#box2 {
left: 120px;
box-shadow: 0 5px 10px black;
}
<div id="box1"></div>
<div id="box2"></div>
This will display incorrectly in Chrome and Firefox like this:
However, it will display correctly in Safari like this:
If I decrease the shadow blur radius in Chrome by a factor of two, I get the expected result:
I have filed a bug report for Chromium and Firefox.
It turns out it wasn't a bug, but an issue with the specification.
For a box shadow the blur value is generated by applying to the shadow a Gaussian blur with a standard deviation equal to half the blur radius. - Robert Longson
A specification issue has been raised here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With