Creating Colorful, Smart Shadows

A bona fide CSS trick from Kirupa Chinnathambi here. To match a colored shadow with the colors in the background-image of an element, you inherit the background in a pseudo-element, kick it behind the original, then blur and filter it. …


The post Creating Colorful, Smart Shadows appeared first on CSS-Tricks.

You can support CSS-Tricks by being an MVP Supporter.


This content originally appeared on CSS-Tricks and was authored by Chris Coyier

A bona fide CSS trick from Kirupa Chinnathambi here. To match a colored shadow with the colors in the background-image of an element, you inherit the background in a pseudo-element, kick it behind the original, then blur and filter it.

.colorfulShadow {
  position: relative;
}

.colorfulShadow::after {
  content: "";
  width: 100%;
  height: 100%;
  position: absolute;
  background: inherit;
  background-position: center center;
  filter: drop-shadow(0px 0px 10px rgba(0, 0, 0, 0.50)) blur(20px);
  z-index: -1;
}

Negative z-index is always a yellow flag for me as that only works if there are no intermediary backgrounds. But the trick holds. There would always be some other way to layer the backgrounds (like a <span> or whatever).

For some reason this made me think of a demo I saw (I can’t remember who to credit!). Emojis had text-shadow on them, which really made them pop. And those shadows could also be colorized to a similar effect.

Direct Link to ArticlePermalink


The post Creating Colorful, Smart Shadows appeared first on CSS-Tricks.

You can support CSS-Tricks by being an MVP Supporter.


This content originally appeared on CSS-Tricks and was authored by Chris Coyier


Print Share Comment Cite Upload Translate Updates
APA

Chris Coyier | Sciencx (2021-05-04T14:19:48+00:00) Creating Colorful, Smart Shadows. Retrieved from https://www.scien.cx/2021/05/04/creating-colorful-smart-shadows-2/

MLA
" » Creating Colorful, Smart Shadows." Chris Coyier | Sciencx - Tuesday May 4, 2021, https://www.scien.cx/2021/05/04/creating-colorful-smart-shadows-2/
HARVARD
Chris Coyier | Sciencx Tuesday May 4, 2021 » Creating Colorful, Smart Shadows., viewed ,<https://www.scien.cx/2021/05/04/creating-colorful-smart-shadows-2/>
VANCOUVER
Chris Coyier | Sciencx - » Creating Colorful, Smart Shadows. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/05/04/creating-colorful-smart-shadows-2/
CHICAGO
" » Creating Colorful, Smart Shadows." Chris Coyier | Sciencx - Accessed . https://www.scien.cx/2021/05/04/creating-colorful-smart-shadows-2/
IEEE
" » Creating Colorful, Smart Shadows." Chris Coyier | Sciencx [Online]. Available: https://www.scien.cx/2021/05/04/creating-colorful-smart-shadows-2/. [Accessed: ]
rf:citation
» Creating Colorful, Smart Shadows | Chris Coyier | Sciencx | https://www.scien.cx/2021/05/04/creating-colorful-smart-shadows-2/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.