I was to have a dialog automatically show up over my hero section (i.e. announcement).

What's it called? And does Kevin have a video on it? Or maybe point me to some examples. Thanks Phil
4 Replies
lko
lko3mo ago
<dialog>? I dont understand what you're looking for
philhoskins
philhoskinsOP3mo ago
when you go to a website and a dialog floats in "Limited time offer" what's that behaviour called?
lko
lko3mo ago
It's a dialog, also called modal
<dialog>
<button autofocus>Close</button>
<p>This modal dialog has a groovy backdrop!</p>
</dialog>
<button>Show the dialog</button>
<dialog>
<button autofocus>Close</button>
<p>This modal dialog has a groovy backdrop!</p>
</dialog>
<button>Show the dialog</button>
::backdrop {
background-image: linear-gradient(
45deg,
magenta,
rebeccapurple,
dodgerblue,
green
);
opacity: 0.75;
}
::backdrop {
background-image: linear-gradient(
45deg,
magenta,
rebeccapurple,
dodgerblue,
green
);
opacity: 0.75;
}
const dialog = document.querySelector("dialog");
const showButton = document.querySelector("dialog + button");
const closeButton = document.querySelector("dialog button");

// "Show the dialog" button opens the dialog modally
showButton.addEventListener("click", () => {
dialog.showModal();
});

// "Close" button closes the dialog
closeButton.addEventListener("click", () => {
dialog.close();
});
const dialog = document.querySelector("dialog");
const showButton = document.querySelector("dialog + button");
const closeButton = document.querySelector("dialog button");

// "Show the dialog" button opens the dialog modally
showButton.addEventListener("click", () => {
dialog.showModal();
});

// "Close" button closes the dialog
closeButton.addEventListener("click", () => {
dialog.close();
});
clevermissfox
clevermissfox3mo ago
Dialog tag, popover api, or toast notification may help you find what you're looking for. Lkos code example is exactly what you would want if using the <dialog> but just as an addition , when styling it in your css make sure you're using the selector
dialog[open] {
/*styles here */
}
dialog[open] {
/*styles here */
}
or you will overwrite it's closed state styles. Many people will change its display to flex or grid then wonder why the dialog won't close. Here's are a couple KPow videos And Steve Griffith Mdn popover api Mdn Dialog
Kevin Powell
YouTube
dialog = the easiest way to make a popup modal
Ever needed to make a modal? Well, we have a native HTML element that does the job with the dialog element! It does a lot of things out of the box that are really awesome, so let’s see how it works! 🔗 Links ✅ Codepen: https://codepen.io/kevinpowell/pen/KKyOYvM ✅ The polyfill: https://github.com/GoogleChrome/dialog-polyfill ✅ a11y modal: htt...
Kevin Powell
YouTube
Styling modals just got easier!
The :modal pseudo-class allows us to style modals nice and easily! 🔗 Links ✅ More on the dialog element: https://youtu.be/TAB_v6yBXIE ⌚ Timestamps 00:00 - Introduction 00:43 - The two different uses for dialog elements 01:36 - Styling the dialog 02:09 - using :modal #css -- Come hang out with other dev's in my Discord Community ...
Steve Griffith - Prof3ssorSt3v3
YouTube
Revealing the Differences between HTML Dialogs and the Popover API
The fully supported HTML dialog element and the newly released Popover API have some overlapping functionality but also a lot of unique features. Watch this to understand the differences. Code from video: https://gist.github.com/prof3ssorSt3v3/f23929f66fb3cd8773f3d7b073df30a6 MDN reference for dialog element: https://developer.mozilla.org/en-U...
MDN Web Docs
: The Dialog element - HTML: HyperText Markup Language | MDN
The HTML element represents a modal or non-modal dialog box or other interactive component, such as a dismissible alert, inspector, or subwindow.
Want results from more Discord servers?
Add your server