Show HN: CSS generator for a high-def glass effect (opens in a new tab)glass3d.dev
420 pointsCross-browser compatibility is actually the reason I rely on ::before and ::after pseudo-elements to build up the effect. Move the color/opacity to the main element, and you’ll get weird color bleed on the corners in Chrome. Move the texture, and it muddles the bevel’s specular highlight. Move the bevel, and it gets blurred out by the backdrop-filter. And so on!
Layers include:
* Adjustable blur, brightness, and saturation (backdrop-filter)
* Subtle translucent texture
* Faux 3D bevel (using box-shadows, not an outline)
Glassmorphism is rather heavy on resources, so it’s best used as an accent and avoided on wide desktop elements.
Should be compatible with recent versions of Chrome, Safari, and Firefox (desktop and mobile). If you spot bugs or rendering glitches, I’d love to know!
Side note: this is an early preview of a framework-agnostic glass SCSS/component library I’m building.
Comments (117) 32 threads
Show all comments
Showing thread 3 of 32
I think the most immediate difference is how light has no interaction with the bevels. I also expect some light to shine back into the glass and affect the lighting and coloring. It's not enough to just throw a blur in there.
Also, glass can have its own shadow with some interesting caustics (not sure even Apple does this). I see the shadow here, and it feels like a simple drop shadow. It makes the box feel like a flat card more than a 3d physical object which I think is part of the new trend.
Either way, This will not be easy to emulate with just css, it's probably more suitable to be a shader running in a gpu.
HTML is dead. I see no reason to care about it because we only need
tags to get some text across, as just about everything else is used to make a webpage an ad-bomb. So let's just start again with the
tag and better gpu integration, and leave everything else out.
They've been trying, with various degrees of success, over the past 10 years with Houdini.
https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_propert...