手风琴的 HTML5 详细信息元素
细节元素在语义上是否适合标记手风琴?
示例:
<div class="accordion">
<details open>
<summary>Section 1</summary>
</details>
<details>
<summary>Section 2</summary>
</details>
<details>
<summary>Section 3</summary>
</details>
</div>
我问这个问题是因为规范对其用法不是很清楚。它只是指出详细信息元素是一个公开小部件。 我当然不想将该元素用于不该做的事情。
编辑
这样的东西在语义上会更合适吗?
<article role="tablist">
<header role="tab" aria-expanded>Section 1</header>
<div role="tabpanel">
</div>
<header role="tab">Section 2</header>
<div role="tabpanel">
</div>
<header role="tab">Section 3</header>
<div role="tabpanel">
</div>
</article>
谢谢!
Is the details element semantically appropriate to markup an accordion?
Example:
<div class="accordion">
<details open>
<summary>Section 1</summary>
</details>
<details>
<summary>Section 2</summary>
</details>
<details>
<summary>Section 3</summary>
</details>
</div>
I ask this question because the spec isn't very clear about its usage. It just states the details element is a disclosure widget.
I certainly don't want to use the element for something that it's not meant to be.
EDIT
Would something like this be better suited semantically?
<article role="tablist">
<header role="tab" aria-expanded>Section 1</header>
<div role="tabpanel">
</div>
<header role="tab">Section 2</header>
<div role="tabpanel">
</div>
<header role="tab">Section 3</header>
<div role="tabpanel">
</div>
</article>
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,
元素完全适合您所描述的内容(和最语义化的选项):
来自http://www.w3.org/html/wg/drafts/html/master/interactive-elements.html#the-details-element:
这是来自 http://html5doctor.com/the-details -和摘要元素/:
完美使用。例如,我的公司有一个包含许多联系选项的联系页面,因此我们可以为其设置一个手风琴,如下所示:
关于样式的注释:良好的语义不应被丢弃来解决特定于浏览器的样式问题。 CSS Reset 可能是有序的,但是有没有语义上的理由不将这些有用且适当的元素用于手风琴。
**请注意:
Chrome 目前是唯一支持切换功能的浏览器,我相信该规范旨在用于这些元素。Javascript 后备在这里会很有用。**编辑 3/2017 - 请参阅 http://caniuse.com/#feat=details 了解支持表。现在除了 IE 和 Edge 之外,几乎所有浏览器都支持此功能。
Yes,
<details><summary>
elements are entirely appropriate (and the most semantic option) for what you're describing:From http://www.w3.org/html/wg/drafts/html/master/interactive-elements.html#the-details-element:
And this is from http://html5doctor.com/the-details-and-summary-elements/:
Perfect usage. For example, my company has a contact page with many contact options so we could setup an accordion for it like so:
A note on styling: good semantics shouldn't be thrown overboard to address browser-specific styling issues. A CSS Reset may be in order, but there's no semantic reason not to use these helpful and appropriate elements for an accordion.
**Do note:
Chrome currently is the only browser that supports the toggling functionality that I believe the spec intended for these elements.A Javascript fallback would be useful here.**Edit 3/2017 - See http://caniuse.com/#feat=details for support tables. This feature is now supported by almost all but IE and Edge.
不要为此使用
,否则您会遇到此问题:
疯狂的 Chrome 问题...Chrome 渲染扭曲?
这可能不是您的手风琴所需的行为。
Don't use
<details>
for this, or you'll have this problem:Insane Chrome issue...Chrome renders twisties?
That's probably not desired behaviour for your accordion.
好问题。我正在寻找它,发现甚至 MDN 也在使用
作为其侧边栏链接菜单。 https://developer.mozilla.org/en-US/ docs/Web/HTML/Element/details
但是,有两个问题:
不可动画
由于它要么打开,要么不打开,所以没有办法为过渡设置动画 - 因为没有过渡。
来自 MDN 文档:
不支持 IE
如果您关心的话,Internet Explorer 不支持它:)
Nice question. I was searching for that and saw even MDN is using
<details>
for their sidebar menu of links. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/detailsHowever, there are two problems:
<details>
isn't animateableSince it's either open or not, there's no way to animate the transition - because there's no transition.
From MDN docs:
No support for IE
If you care, it is not supported by Internet explorer :)