Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
October 20, 2021 03:12 pm GMT

box-shadow vs drop-shadow() in CSS



In this article, we will see the difference between the box-shadow and drop-shadow(). The box-shadow is a CSS property but drop-shadow() is a function. Both box-shadow and drop-shadow() are used to cast a shadow. The difference between them is, the box-shadow property creates a rectangular shadow behind an element's entire box, while the drop-shadow() filter function creates a shadow that conforms to the shape (alpha channel) of the image itself.

In simple words, while working with the transparent images if you use the drop-shadow()filter function it will create a shadow on the image's content and if you use the box-shadow property it will create a rectangular shadow behind an element's entire box.

In case of text content,drop-shadow()works similar to the text-shadow property.

Their syntax is,


filter: drop-shadow(offset-x offset-y blur-radius color);

box-shadow: offset-x offset-y blur-radius color ;

Demo Code is,

<!DOCTYPE html><html lang="en">  <head>    <meta charset="UTF-8" />    <meta http-equiv="X-UA-Compatible" content="IE=edge" />    <meta name="viewport" content="width=device-width, initial-scale=1.0" />    <title>box-shadow vs drop-shadow</title>    <style>      .img-1 {        filter: drop-shadow(0 0 5px black);      }      .img-2 {        box-shadow: 0 0 5px black;      }    </style>  </head>  <body>    <img      class="img-1"      src="https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png"      alt="google.logo"    />    <img      class="img-2"      src="https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png"      alt="google.logo"    />  </body></html>

Also Read:


Original Link: https://dev.to/keshavs759/box-shadow-vs-drop-shadow-in-css-cep

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To