< label>的语义用法也是一个< form>? [英] Semantic use of <label> also out of a <form>?

查看:88
本文介绍了< label>的语义用法也是一个< form>?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对使用标签标签表示怀疑。

I have a doubt about using the tag label.

我有 div 充当小部件,模拟高级下拉列表。

I have a div acting as a widget that simulates an advanced dropdown-list.

<div class="control">
    <label class="description">Choose:</label>
    <div class="widget__list">...some other content...</div>
</div>

这里是W3C规范( http://www.w3.org/TR/html401/interact/forms.html#h-17.9 )说:

Here the W3C specifications (http://www.w3.org/TR/html401/interact/forms.html#h-17.9) say:


LABEL元素用于指定没有隐式标签的控件的标签

The LABEL element is used to specify labels for controls that do not have implicit labels

(更新:请不要依赖上面的(过时的)报价。请参阅下面链接的 HTML5规范

(UPDATE: Please don't rely on the (outdated) quote above. Refer to HTML5 specs linked below)

滚动到控件部分( http://www.w3.org/TR/html401/interact/forms.html#h-17.2 )我可以在控件类型列表中看到菜单类型

Scrolling up to the "Controls" section (http://www.w3.org/TR/html401/interact/forms.html#h-17.2) I can see that in the list of "control types" there is the type menu.

我想知道的是:


  • 我的div-widget是否属于菜单控件的类别

  • 如果是,我的小部件应该是wr吗? apped到表单元素,即使我没有任何HTML本机控件(输入选择按钮等)?

  • am我错误地使用 label 元素(不在表单的上下文中),我应该将其更改为 span

  • does my div-widget belong to the category of menu controls?
  • if yes, should my widget be wrapped into a form element, even if I don't have any HTML native control (input, select, button, etc.) in it?
  • am I using incorrectly the label element (not being in the context of a form), and should I maybe change it to span?

这些问题的语义最正式答案是什么?

What are the most semantically formal answers to these questions?

引用是指HTML4规范,导致提出上述问题。
标签 已经提供了我需要的答案(感谢 @PeterKrauss )。

The quote refers to the HTML4 specs, leading to raise the above questions. The current HTML5 specs for label gives already the answers that I needed (thanks @PeterKrauss).

推荐答案

您的文件是根据W3C验证器有效。

这意味着您的标签案例没有定义作为当前HTML标准中的错误。所以你不应该更担心语义,只要你在这里使用它 - 如果它对你来说很自然,并且它是否按预期工作。

That means your label case isn’t defined as an error in the current HTML standard. So you shouldn’t worry more about the semantics, and just use it as you have here—if it’s natural for you and if it works as expected.


向上滚动到控件部分( http ://www.w3.org/TR/html401/interact/forms.html#h-17.2

您不希望使用旧的HTML4规范。它发表于1999年。

You don’t want to use the old HTML4 spec for anything. It was in published in 1999.

当前的HTML标准位于 https://html.spec.whatwg.org/multipage/ 标签元素上该规范的部分位于 https://html.spec.whatwg.org/multipage/forms.html#the-label-element

The current HTML standard is at https://html.spec.whatwg.org/multipage/. The section of that spec on the label element is at https://html.spec.whatwg.org/multipage/forms.html#the-label-element.


我的div-widget是否属于菜单控件的类别?

does my div-widget belong to the category of menu controls?

当前的HTML标准没有定义一个名为菜单控件的类别;所以标签元素是否适合作为一个类别无关紧要。

The current HTML standard doesn’t define a category called "menu controls"; so it doesn’t matter whether the label element fits into that as a category.


<我是否错误地使用了标签元素(不在表格的上下文中),我应该将其更改为跨度吗?

am I using incorrectly the label element (not being in the context of a form), and should I maybe change it to span?

你没有错误地使用它。如果你是,W3C验证器会将其标记为错误。换句话说,您的案例未在当前HTML标准中定义为错误。所以你很高兴。

You’re not using it incorrectly. If you were, the W3C validator would flag it as an error. In other words, your case isn’t defined as an error in the current HTML standard. So you’re good to go.

这篇关于&lt; label&gt;的语义用法也是一个&lt; form&gt;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆