模态对话框的语义准确的 HTML5 元素
我想知道我的一些 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在这种情况下,模式与引发它的操作“不相关”。虽然您通常可能期望侧边栏中有旁注,但语义内容的目的之一是实现不受物理页面特征限制的多功能性。规范的最后一句话似乎暗示了这种多功能的用例。
<aside>
seems appropriate. The current spec with relevant sections bolded: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.
当前的 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.)
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 年开始,您可以使用 HTML5 提供的对话框 API。
https://developer.mozilla.org/en-US/文档/Web/HTML/Element/dialog
As of 2024 you can use the Dialog API that HTML5 provides.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dialog