标签 标签语义
我已阅读此并且我通常使用跨度或强项描述“文本标签”。对于最佳实践来说这是真的吗?这似乎也是一种语义方式,但为什么仅限于表单元素呢?
如果我想显示这样的信息怎么办:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该使用定义列表(
dl
与dt
和dd
):规范指出它可用于
我认为也可以使用
table
(带有th
)。但我只会在想要比较几个人时使用它,而不仅仅是列出一个人的数据。You should use a definition list (
dl
withdt
anddd
):The spec states that it could be used for
I think a
table
(withth
) 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.我会避免使用
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 aspan
(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).
我想如果你想在语义上 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.