DEV Community

Alex Yumashev
Alex Yumashev

Posted on • Originally published at jitbit.com

1

CSS shadows trick

I notice a lot of websites and apps using "box-shadow" like this:

box-shadow: 0px 0px 20px 5px #ddd

Which literally means "let's have a #ddd-colored shadow, with zero offset, 5 pixels wide and 20 pixels blurred". And it's perfectly normal, for the most part.

There's only one problem:

Glow shadow

See, the shadow looks pretty cool when positioned over the light background. But as soon as it moves over to the dark side (top area) - you get the ugly "glow" around your box.

The solution is to always use black semi-transparent shadows like this:
box-shadow: 0px 0px 20px 5px rgba(0,0,0,0.15) which now says "use a black shadow, but make it 15% transparent".

Normal shadow

Perfectly supported by IE9 and later. And as a bonus you get more consistent shadows across Firefox/Chrome which has always been an issue ("grey" shadows look darker in Firefox than Chrome).

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (0)

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay