Loading video...

Video Failed to Load

Go Home

For your stacked elements: Stop using border or box-shadow. Start using mask.

191,373 views • 1 year ago •via X (Twitter)

10 Comments

Brotzky's profile picture
Brotzky1 year ago

There are always issues when you use box-shadow, border, or outline for this. You forget to change the color so it mismatches the background. You want to add hover interactions so you need to transition both. The CSS is quite simple:

Λbstract's profile picture
Λbstract1 year ago

RT @InstaMAT_io: 👀 Are you looking for an alternative to Adobe Substance tools? Do not miss out on InstaMAT from killer node-based material…

Brotzky's profile picture
Brotzky1 year ago

Another wonderful trick: clip-path with SVGs. It's a lot easier to customize in tools like Figma as well.

Adam Wathan's profile picture
Adam Wathan1 year ago

I had to give up on this approach when I wanted to be able to make an avatar translate up on hover and stuff like that — found any solution to that set of problems?

alex's profile picture
alex1 year ago

elite

Brotzky's profile picture
Brotzky1 year ago

now u r too

Vini's profile picture
Vini1 year ago

mask is also pretty good to create that fade out effect

T. Costa's profile picture
T. Costa1 year ago

This is the way

Robert Menke's profile picture
Robert Menke1 year ago

✍️✍️✍️

matt's profile picture
matt1 year ago

Working on a stacked cards design and gonna get rid of the box-shadows and try this!

Related Videos

CSS Trick! 🤙 You can create gradient borders on translucent elements using mask-clip and mask-composite with a pseudo-element 🔥 .gradient-border::after { mask-clip: padding-box, border-box; mask-composite: intersect; mask: linear-gradient(transparent, transparent), linear-gradient(white, white); } It's the same "Transparent border trick" from before. But, now you apply it to a pseudo-element 😎 The trick is to create a pseudo-element with a gradient background and then mask it so we only see the part we want, the border ✨ mask-clip defines the area affected by a mask. Similar to how you can define background-size. Using padding-box and border-box constrains the two masks. mask-composite is the magic part ✨ It defines a compositing operation for stacked mask layers. Using intersect means that the parts that overlap get replaced. And this seems to work in all browsers 🙌 As for the rest of the styles... – Make sure you set pointer-events: none on the pseudo-element – Make sure it fills the parent element. You can use position: absolute and inset: 0 – Make sure the background fills the space including the border-width. You can use calc to achieve that: --bg-size: calc(100% + (2px * var(--border))); background: var(--gradient) center center / var(--bg-size) var(--bg-size); That's it! 🚀 Gradient borders on translucent elements. You can set all the backdrop-filter: blur() you like! 😅 CodePen.IO link below! 👇

jhey ʕ•ᴥ•ʔ

269,739 views • 2 years ago