Use CSS filter to Create a Drop Shadow

Jhey Tompkins
InstructorJhey Tompkins
Share this video with your friends

Social Share Links

Send Tweet
Published 4 years ago
Updated 3 years ago

In this lesson, we look at how you can use the CSS filter property to create a drop shadow effect around an element's content. We use the drop-filter function on an image to start and then a combination of elements.

Jhey Tompkins: [0:00] We want to apply a drop shadow to this image, a shadow that follows the outline of our image. This image is a transparent png. We may initially reach for the box-shadow property, but this won't work because it applies shadow to the box modal of our image.

[0:17] To achieve that drop shadow effect we can use the CSS filter property with the drop-shadow() function. We are going to match as closely to our box-shadow, so we have an offset-x of 10px, an offset-y of 10px, a blur-radius of 10px and we use the same color as we did for the box-shadow. Now we have a drop shadow that follows the outline of our image.

[0:41] It's worth noting that the blur-radius and the color are both optional, but this results in a much harsher drop shadow with no blurring and black as the default color. We can apply a drop shadow to any element. Here we've updated our image to be enclosed within a figure tag and it also has a caption.

[1:00] Instead of applying the drop shadow to the image, we now apply it to the containing element, which is the figure element. We can see how that drop shadow follows the outline of the figure element's children, the image and the fake caption.

[1:14] In review we can use CSS filter property with the drop-shadow function to create a drop shadow around an element's content. This is particularly useful where the outline of an element's content is not basic, where we might have previously opted to use a box shadow.

egghead
egghead
~ an hour ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today