HTML popover Attribute

Date:

Share post:

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.

https://codepen.io/darkwing/pen/yLrqEvK

Request Metrics real user monitoring
Request Metrics real user monitoring
Request Metrics real user monitoring
Request Metrics real user monitoring
  • 5 Ways that CSS and JavaScript Interact That You May Not Know About
  • Introducing MooTools Templated

    Introducing MooTools Templated

    One major problem with creating UI components with the MooTools JavaScript framework is that there isn’t a great way of allowing customization of template and ease of node creation. As of today, there are two ways of creating: new Element Madness The first way to create UI-driven…

  • Create a NoScript Compatible Select Form Element with an onChange Event
  • Drag. Drop. Lock.

Source link
spot_img

Related articles

Simplifying the AI stack: The key to scalable, portable intelligence from cloud to edge

Presented by ArmA simpler software stack is the key to portable, scalable AI across cloud and edge. AI...

Pokémon Legends Z-A Is The Creepiest Entry Yet, Not In A Good Way

There’s been quite a lot of talk recently about the lack of voiceover work in Pokemon Legends: Z-A,...

Sam the Vendor – Darknet Diaries

Full Transcript Sam Bent, a.k.a. DoingFedTime, brings us a story of what it was like...

Apple Unveils New iPhone 17 Lineup, Updated Apple Watches, and AirPods Pro 3

In the tech world, September brings the fruits of Apple’s harvest: new iPhones, Apple Watches, and AirPods. At...