The elevation-* utilities are built on box-shadow. They are great, but box-shadow has two major limitations.
- It’s a pain in the ass to transition
box-shadow - and
box-shadowcannot conform to other shapes
A much more useful shadow is drop-shadow because it counters both of these major limitations.
.selector { filter: drop-shadow(/* ... */);}For the rest of this lesson let’s assume we’re working with a blob.
<svg viewBox="0 0 200 200"> <path fill="currentcolor" d="M72.1,-22.4C81.3,4.7,68.1,40.2,42.9,58.3C17.7,76.4,-19.5,77.2,-39.2,61.1C-58.9,45.1,-61.1,12.3,-51.6,-15.3C-42.2,-42.9,-21.1,-65.2,5.2,-66.9C31.5,-68.6,63,-49.6,72.1,-22.4Z" transform="translate(100 100)" /></svg>Drop-shadow elevation utilities
Since drop-shadow is so useful, I built the same set of elevation utilities for drop shadow, and I named them ds-elevation-*. The features are identical to the elevation-*, but you just can’t adjust --shadow-spread because drop-shadow doesn’t support it.
<div class="ds-elevation-1">...</div><div class="ds-elevation-2">...</div><div class="ds-elevation-3">...</div><div class="ds-elevation-4">...</div><div class="ds-elevation-5">...</div><div class="ds-elevation-6">...</div><div class="ds-elevation-7">...</div>Here’s the difference between box-shadow and drop-shadow (and hence, between elevation and ds-elevation) when they are applied to the blob above.
<!-- box-shadow --><svg class="elevation-*">...</svg>
<!-- drop-shadow --><svg class="ds-elevation-*">...</svg>Box shadow
Drop shadow
Transitioning drop shadows
Drop shadows are much easier to transition. We just need to change the drop-shadow filter and run a transition at the same time.
It looks like this in CSS:
.selector { filter: drop-shadow(/* old shadow here */) transition: filter ease-out 300ms;
/* And other interactive states */ &:hover { filter: drop-shadow(/* new shadow here */) }}And we can use the interact variant we have created before to make this transition on any interaction.
<svg class="transition ds-elevation-3 interact:ds-elevation-5 ">...</svg>I think this is really cool and easy to use.
Welcome! Unfortunately, you don’t have access to this lesson. To get access, please purchase the course or enroll in Magical Dev School.
Unlock this lesson