Modals have been an important part of websites for two decades. Stacking contents and using fetch
to accomplish tasks are a great way to improve UX on both desktop and mobile. Unfortunately most developers don’t know that the HTML and JavaScript specs have implemented a native modal system via the popover
attribute — let’s check it out!
The HTML
Creating a native HTML modal consists of using the popovertarget
attribute as the trigger and the popover
attribute, paired with an id
, to identify the content element:
This is the contents of the popover
Upon clicking the button
, the popover will open. The popover, however, will not have a traditional background layer color so we’ll need to implement that on our own with some CSS magic.
The CSS
Styling the contents of the popover content is pretty standard but we can use the browser stylesheet selector’s pseudo-selector to style the “background” of the modal:
/* contents of the popover */ [popover] { background: lightblue; padding: 20px; } /* the dialog's "modal" background */ [popover]:-internal-popover-in-top-layer::backdrop { background: rgba(0, 0, 0, .5); }
:-internal-popover-in-top-layer::backdrop
represents the “background” of the modal. Traditionally that UI has been an element with opacity such to show the stacking relationship.
CSS Filters
CSS filter support recently landed within WebKit nightlies. CSS filters provide a method for modifying the rendering of a basic DOM element, image, or video. CSS filters allow for blurring, warping, and modifying the color intensity of elements. Let’s have…
CSS calc
CSS is a complete conundrum; we all appreciate CSS because of its simplicity but always yearn for the language to do just a bit more. CSS has evolved to accommodate placeholders, animations, and even click events. One problem we always thought…
MooTools, Mario, and Portal
I’m a big fan of video games. I don’t get much time to play them but I’ll put down the MacBook Pro long enough to get a few games in. One of my favorites is Portal. For those who don’t know, what’s…