Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does box-shadow look different than filter: drop-shadow

Tags:

html

browser

css

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: enter image description here

Firefox/OS X: enter image description here

like image 863
ernesto Avatar asked Sep 19 '16 14:09

ernesto


People also ask

How is the box shadow different from text shadow?

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 the effect of drop shadow to the image?

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.

Which property apply a drop shadow around the visible element box?

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.

What visual effect does a drop shadow add to an object?

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.


1 Answers

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:

Chrome fail

However, it will display correctly in Safari like this:

Safari ok

If I decrease the shadow blur radius in Chrome by a factor of two, I get the expected result:

Chrome adjusted

I have filed a bug report for Chromium and Firefox.

UPDATE: January 12, 2017

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.

like image 68
Zoyt Avatar answered Sep 28 '22 02:09

Zoyt