Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Sunshine And March Vibes (2025 Wallpapers Edition)

      May 16, 2025

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      May 16, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      May 16, 2025

      How To Prevent WordPress SQL Injection Attacks

      May 16, 2025

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025

      Bing Search APIs to be “decommissioned completely” as Microsoft urges developers to use its Azure agentic AI alternative

      May 16, 2025

      Microsoft might kill the Surface Laptop Studio as production is quietly halted

      May 16, 2025

      Minecraft licensing robbed us of this controversial NFL schedule release video

      May 16, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      The power of generators

      May 16, 2025
      Recent

      The power of generators

      May 16, 2025

      Simplify Factory Associations with Laravel’s UseFactory Attribute

      May 16, 2025

      This Week in Laravel: React Native, PhpStorm Junie, and more

      May 16, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025
      Recent

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025

      Bing Search APIs to be “decommissioned completely” as Microsoft urges developers to use its Azure agentic AI alternative

      May 16, 2025

      Microsoft might kill the Surface Laptop Studio as production is quietly halted

      May 16, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»Poppin’ In

    Poppin’ In

    June 26, 2024

    Oh, hey there! It’s been a hot minute, hasn’t it? Thought I’d pop in and say hello. 👋

    Speaking of “popping” in, I’ve been playing with the Popover API a bit. We actually first noted it wayyyyy back in 2018 when Chris linked up some information about the <dialog> element. But it’s only been since April of this year that we finally have full Popover API support in modern browsers.

    There was once upon a time that we were going to get a brand-new <popover> element in HTML for this. Chromium was working on development as recently as September 2021 but reached a point where it was dropped in favor of a popover attribute instead. That seems to make the most sense given that any element can be a popover — we merely need to attach it to the attribute to enable it.

    <div popover>
    <!– Stuff –>
    </div>

    This is interesting because let’s say we have some simple little element we’re using as a popover:

    <div>👋</div>

    If this is all the markup we have and we do absolutely nothing in the CSS, then the waving emoji displays as you might expect.

    CodePen Embed Fallback

    Add that popover attribute to the mix, however, and it’s gone!

    CodePen Embed Fallback

    That’s perhaps the first thing that threw me off. Most times something disappears and I assume I did something wrong. But cracking open DevTools shows this is exactly what’s supposed to happen.

    The element is set to display: none by default.

    There may be multiple popovers on a page and we can differentiate them with IDs.

    <div popover id=”tooltip”>
    <!– Stuff –>
    </div>

    <div popover id=”notification”>
    <!– Stuff –>
    </div>

    That’s not enough, as we also need some sort of “trigger” to make the popover, well, pop! We get another attribute that turns any button (or <input>-flavored button) into that trigger.

    <button popovertarget=”wave”>Say Hello!</button>
    <div popover id=”wave”>👋</div>

    Now we have a popover “targeted ” to a <button>. When the button is clicked, the popover element toggles visibility.

    CodePen Embed Fallback

    This is where stuff gets really fun because now that CSS is capable of handling logic to toggle visibility, we can focus more on what happens when the click happens.

    Like, right now, the emoji is framed by a really thick black border when it is toggled on. That’s a default style.

    Notice that the border sizing in the Box Model diagram.

    A few other noteworthy things are going on in DevTools there besides the applied border. For example, notice that the computed width and height behave more like an inline element than a block element, even though we are working with a straight-up <div> — and that’s true even though the element is clearly computing as display: block. Instead, what we have is an element that’s sized according to its contents and it’s placed in the dead center of the page. We haven’t even added a single line of CSS yet!

    Speaking of CSS, let’s go back to removing that default border. You might think it’s possible by declaring no border on the element.

    /* Nope 👎 */
    #wave {
    border: 0;
    }

    There’s actually a :popover-open pseudo-class that selects the element specifically when it is in an “open” state. I’d love this to be called :popover-popped but I digress. The important thing is that :popover-open only matches the popover element when it is open, meaning these styles are applied after those declared on the element selector, thus overriding them.

    CodePen Embed Fallback

    Another way to do this? Select the [popover] attribute:

    /* Select all popovers on the page */
    [popover] {
    border: 0;
    }

    /* Select a specific popover: */
    #wave[popover] {
    border: 0;
    }

    /* Same as: */
    #wave:popover-open {
    border: 0;
    }

    With this in mind, we can, say, attach an animation to the #wave in its open state. I’m totally taking this idea from one of Jhey’s demos.

    CodePen Embed Fallback

    Wait, wait, there’s more! Popovers can be a lot like a <dialog> with a ::backdrop if we need it. The ::backdrop pseudo-element can give the popover a little more attention by setting it against a special background or obscuring the elements behind it.

    I love this example that Mojtaba put together for us in the Almanac, so let’s go with that.

    CodePen Embed Fallback

    Can you imagine all the possibilities?! Like, how much easier will it be to create tooltips now that CSS has abstracted the visibility logic? Much, much easier.

    CodePen Embed Fallback

    Michelle Barker notes that this is probably less of a traditional “tooltip” that toggles visibility on hover than it is a “toggletip” controlled by click. That makes a lot of sense. But the real reason I mention Michelle’s post is that she demonstrates how nicely the Popover API ought to work with CSS Anchor Positioning as it gains wider browser support. That will help clean out the magic numbers for positioning that are littering my demo.

    Here’s another gem from Jhey: a popover doesn’t have to be a popover. Why not repurpose the Popover API for other UI elements that rely on toggled visibility, like a slide-out menu?

    CodePen Embed Fallback

    Oh gosh, look at that: it’s getting late. There’s a lot more to the Popover API that I’m still wrapping my head around, but even the little bit I’ve played with feels like it will go a long way. I’ll drop in a list of things I have bookmarked to come back to. For now, though, thanks for letting me pop back in for a moment to say hi.

    On popover accessibility: what the browser does and doesn’t do (Hidde de Vries)

    If you’re using popover, also use the dialog element for your modal dialogs 📺(Hidde de Vries)

    Open UI and the Popover API (Brecht De Ruyte)

    Brief Note on Popovers with Dialogs (Adrian Roselli)

    Advanced Form Control Styling With Selectmenu And Anchoring API (Brecht De Ruyte)

    Using the Popover API for HTML Tooltips (Chris Coyier)

    Comparing the Popover API and the <dialog> element (LogRocket)

    Poppin’ In originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleAttack of the clones: Getting RCE in Chrome’s renderer with duplicate object properties
    Next Article khard – console vcard client

    Related Posts

    Security

    Nmap 7.96 Launches with Lightning-Fast DNS and 612 Scripts

    May 17, 2025
    Common Vulnerabilities and Exposures (CVEs)

    CVE-2024-47893 – VMware GPU Firmware Memory Disclosure

    May 17, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    How to Use Django Signals in Your Projects

    Development

    Mega Casino World: Why MCW is the Ultimate Destination for Gamblers

    Learning Resources

    Top kitchen remodeling companies in New Hudson, Michigan

    Development

    159 CVEs Exploited in Q1 2025 — 28.3% Within 24 Hours of Disclosure

    Development

    Highlights

    MLB The Show 25’s absence from Game Pass may push the game’s fall

    January 30, 2025

    Sony skips Xbox Game Pass for this year’s MLB The Show 25 game, but it…

    Ghostty DEB Installers Now Available for Ubuntu 25.04

    April 21, 2025

    Text Alternatives Testing: Boost Web Accessibility in 2024

    August 1, 2024

    ScyllaDB: La Transizione a una Licenza “Source Available” e le Sue Conseguenze

    December 23, 2024
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.