模态对话框的语义准确的 HTML5 元素

发布于 2024-09-06 20:30:17 字数 581 浏览 2 评论 0原文

我想知道我的一些 Web 开发人员/设计师同事认为什么是用于模态对话框(例如 lightbox、superbox、thickbox 或任何您最喜欢的风格)的最佳 HTML 5 元素。

由于这些类型的 UI 不遵循“正常”网页的典型流程(显然,根据 HTML 5 规范专家的说法,该网页本质上是一个博客),因此它们并不像

当然,总是有

,但是,我只是想可能有一些语义上更准确的东西。

不幸的是,没有 元素。您对于规范中是否应该包含这一内容有何看法?既然该元素不存在,那么您的下一个最佳选择是什么?

I was wondering what some of my fellow web developers/designers felt would be the best HTML 5 element to use for a modal dialog like a lightbox, superbox, thickbox, or whatever your favorite flavor might happen to be.

Since these types of UI's don't follow the typical flow of a 'normal' web page (which, apparently, according to HTML 5 spec gurus is, essentially, a blog), they don't really fall into place like a <header>,<nav>,<section>, <article>, or a <footer> (amongst other new 'semantic' elements) might.

Of course, there is always the <div>, but, I was just kinda thinking there might be something a little more semantically-accurate.

Unfortunately, there is no <modal> element. What are your thoughts on whether there should be one in the spec? And since the element doesn't exist, what would be your next best choice?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

尽揽少女心 2024-09-13 20:30:17

aside元素代表一个部分
由内容组成的页面
与切线相关的
side 元素周围的内容,以及
这可以被认为是单独的
来自该内容。
这些部分是
通常表示为侧边栏
印刷版式。

该元素可用于
印刷效果,例如引言
或侧边栏,用于广告,用于
导航元素组,以及其他
被视为单独的内容
从页面的主要内容。

在这种情况下,模式与引发它的操作“不相关”。虽然您通常可能期望侧边栏中有旁注,但语义内容的目的之一是实现不受物理页面特征限制的多功能性。规范的最后一句话似乎暗示了这种多功能的用例。

<aside> seems appropriate. The current spec with relevant sections bolded:

The aside element represents a section
of a page that consists of content
that is tangentially related to the
content around the aside element, and
which could be considered separate
from that content.
Such sections are
often represented as sidebars in
printed typography.

The element can be used for
typographical effects like pull quotes
or sidebars, for advertising, for
groups of nav elements, and for other
content that is considered separate
from the main content of the page.

In this case, a modal is "tangentially related" to the action that caused it. While you might normally expect an aside to be in a sidebar, one of the purposes of semantic content is to enable versatility that's unrestricted by physical page characteristics. The last phrase of the spec seems to imply just this versatile use case.

我ぃ本無心為│何有愛 2024-09-13 20:30:17

当前的 HTML 草案有一个 dialog 元素。它曾一度被删除,但现在又回来了,并且浏览器开始实现它。 (编辑:到 2022 年,它会出现在所有现代浏览器中。)

对话框元素代表用户可以使用的应用程序的一部分
交互以执行任务,例如对话框、检查器、
或窗口。

为了可访问性(直到该元素得到更广泛的支持),我还将包含 对话框 ARIA 角色

要在本身不支持

元素的浏览器中获取 JavaScript API,您可以使用 polyfill

The current draft of HTML has a dialog element. It was removed at one point but it's back, and browsers are starting to implement it. (Edit: in 2022, it’s in all modern browsers.)

The dialog element represents a part of an application that a user
interacts with to perform a task, for example a dialog box, inspector,
or window.

For accessibility (until the element is more widely supported) I would also include the dialog ARIA role.

To get the JavaScript API in browsers that don't natively support the <dialog> element, you can use a polyfill.

沙沙粒小 2024-09-13 20:30:17

从 2024 年开始,您可以使用 HTML5 提供的对话框 API。

<dialog open>
  <p>Greetings, one and all!</p>
  <form method="dialog">
    <button>OK</button>
  </form>
</dialog>

https://developer.mozilla.org/en-US/文档/Web/HTML/Element/dialog

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();
});

As of 2024 you can use the Dialog API that HTML5 provides.

<dialog open>
  <p>Greetings, one and all!</p>
  <form method="dialog">
    <button>OK</button>
  </form>
</dialog>

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dialog

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();
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文