标签 标签语义

发布于 2024-10-25 06:52:16 字数 538 浏览 3 评论 0原文

我已阅读并且我通常使用跨度或强项描述“文本标签”。对于最佳实践来说这是真的吗?这似乎也是一种语义方式,但为什么仅限于表单元素呢?

如果我想显示这样的信息怎么办:

Name: FOo Bar
Age: 27
Weight: 151 kg

等等?

姓名、年龄和体重都可以被描述为标签,但由于它们描述的项目不是输入标签,因此它在语义上不正确(至少对于 html 和 w3c 而言)。我通常使用

<span class="label"> or <span class="description"> or <span class="person-detail"> etc

,但通常还应该有一个不属于输入字段的标签。因为这可能有点主观,我不介意将其变成社区维基或其他东西

I've read this and I GENERALLY use spans or strongs to describe "text-labels". Is this true for best practices? It seems is also a semantic way but why is it limited to just form elements?

What if I wanted to display information as this:

Name: FOo Bar
Age: 27
Weight: 151 kg

etc?

name, age, and weight can all be described as labels, but since the items they're describing aren't input tags, it isn't semantically correct(for html and w3c at least). I usually use

<span class="label"> or <span class="description"> or <span class="person-detail"> etc

but generally there should also be a tag for labels that don't pertain to input fields. As this might be a bit subjective I don't mind this turning into a community wiki or something

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

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

发布评论

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

评论(3

漫漫岁月 2024-11-01 06:52:16

您应该使用定义列表dldtdd):

<dl>

 <dt>Name</dt>
 <dd>FOo Bar</dd>

 <dt>Age</dt>
 <dd>27</dd>

 <dt>Weight</dt>
 <dd>151 kg</dd>

</dl>

规范指出它可用于

术语和定义、元数据主题和值、问题和答案或任何其他名称-值数据组。


我认为也可以使用table(带有th。但我只会在想要比较几个人时使用它,而不仅仅是列出一个人的数据。

You should use a definition list (dl with dt and dd):

<dl>

 <dt>Name</dt>
 <dd>FOo Bar</dd>

 <dt>Age</dt>
 <dd>27</dd>

 <dt>Weight</dt>
 <dd>151 kg</dd>

</dl>

The spec states that it could be used for

terms and definitions, metadata topics and values, questions and answers, or any other groups of name-value data.


I think a table (with th) could be used, too. But I would only use it when I want to compare several people, not just listing the data of one person.

剩一世无双 2024-11-01 06:52:16

我会避免使用 label 标记,除非它与功能性 HTML 表单(带有可编辑字段)结合使用;否则,使用它可能会在语义上造成混乱。

span 标记没有语义含义,无论添加到其中的 id 或类如何,也无论使用它的上下文如何。使用 span 在语义上不会获得任何好处(尽管它没有什么坏处)。

strong 标记具有通用含义(此内容具有额外的重要性),不会根据其使用的上下文而变化。有时,当没有其他更合适的方法时,它会很有用。

在这种特殊情况下,定义列表(如@unor建议的)似乎是可行的方法。如果需要高级样式,请将每个名称/值对放入单独的定义列表中(这在语义上可能很尴尬,但它可以在内容样式方面提供更大的灵活性)。

I'd avoid using a label tag unless it's in combination with a functional HTML form (with editable fields); otherwise, using it may be semantically confusing.

A span tag has no semantic meaning, regardless of the id or class added to it, and regardless of the context in which it's used. You don't gain anything semantically by using a span (though it does no harm).

A strong tag has a generic meaning (this content has extra importance) that doesn't vary based on the context in which it's used. It's sometimes useful when there's nothing else more appropriate.

In this particular case, a definition list (as suggested by @unor) seems like the way to go. If advanced styling is required, put each name-value pair into a separate definition list (which may be awkward semantically, but it allows greater flexibility with styling the content).

北陌 2024-11-01 06:52:16

我想如果你想在语义上 100% 正确,你就必须将标签与禁用或只读文本框结合使用,这些文本框的样式看起来有点不同。

I guess if you wanted to be 100% semantically correct you'd have to use labels in conjunction with disabled or readonly text boxes that have been styled to look a bit different.

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