Notification Web Component with Intrinsic Scaling
I set out to reproduce the effect from "The CSS Hack You Need To
Know", which is all about
using the attr()
CSS function to extract an attribute's value from the tag being styled so you can
apply it to a ::after
entry that will display the attribute. The idea is that one could then set:
<div class="notification-bell-container" current-count=5><svg ...></svg> </div>
And get back something that looks like this:
As I was playing with the source code, I realized that it had one major shortcoming: it didn't scale well. For every different size, if you wanted the notification circle to be even approximately in the right place you would need to hand-code the location of the counter and have breakpoint-oriented versions for phone, tablet, desktop, extra-wide, and ten-foot displays.
Can we do better than that? With web components we can do anything.