HTML:表单之外的“标签”的最佳标签 [英] HTML: Best tag for 'labels' outside of forms

查看:342
本文介绍了HTML:表单之外的“标签”的最佳标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您将使用哪些HTML标签来获取这类信息:
年龄:40
城市:法兰克福

国家:德国

状态:有效





我喜欢在这里使用 p 标签中的< label> 标签,这听起来像很好的语义。但是,这些信息不在表单内。 W3C 称:

label:标签元素表示表单控件的标题。



那么用?我可以清楚地使用< strong> ,但是这没有'强烈的重要性',并且感觉不正确。



更新



注意到定义清单建议后,我想问问这是否仍然是最好的如果我在同一页面上有几条这样的信息?这将意味着我用几次不同的定义来定义名称。例如:



姓名:John

年龄:$
城市:法兰克福

国家:德国

状态:活动





姓名:Maria

年龄:30

城市:波恩

国家/地区:德国/>
状态:无效




< dl> 仍然是最好的选择? 定义列表可能适用于此处:

 < DL> 
< dt>名称< / dt>
< dd> John< / dd>
< dt>年龄< / dt>
< dd> 40< / dd>
< dt>城市< / dt>
< dd>法兰克福< / dd>
< dt>国家< / dt>
< dd>德国< / dd>
< dt>状态< / dt>
< dd>有效< / dd>
< / dl>




http://www.w3.org/TR/html401/struct/lists.html#h-10.3 - 定义列表,使用DL元素,通常由一系列的术语/定义对组成(尽管定义列表可能有其他应用程序)。

然而,仅仅因为你想要粗体格式并不意味着你被限制为< strong> < b> 。您可以使用非语义的< span> ,并简单地使用CSS来格式化。

另外,您可以使用CSS添加冒号,而不是将它们放入标记中:

  dt:after {content:: ; } 

也许为了澄清一些关于它正确用法的混淆,它看起来像HTML5将指此标记作为描述列表


http://www.w3.org/TR/html5/grouping-content.html#the-dl-element - dl元素表示由零个或多个名称 - 值组(一个描述列表)组成的关联列表。



What HTML tags would you use in for this kind of information:


Name: John
Age: 40
City: Frankfurt
Country: Germany
Status: Active


I like to use the <label> tag within p tags here, which sounds like good semantics. However, this information is NOT inside a form. And the W3C says:

label: The label element represents a caption for a form control.

So what should I use then? I can clearly use <strong>, but this has no 'strong importance' and does not feel correct.

UPDATE

After noticing the DEFINITION LIST suggestion, I'd like to ask if this would still be best if I have several pieces of this information on the same page? It would mean I define "name" with a different "definition" several times. Eg:


Name: John
Age: 40
City: Frankfurt
Country: Germany
Status: Active


Name: Maria
Age: 30
City: Bonn
Country: Germany
Status: Inactive


Is <dl> still the best way to go?

解决方案

A definition list could be suitable here:

<dl>
    <dt>Name</dt>
    <dd>John</dd>
    <dt>Age</dt>
    <dd>40</dd>
    <dt>City</dt>
    <dd>Frankfurt</dd>
    <dt>Country</dt>
    <dd>Germany</dd>
    <dt>Status</dt>
    <dd>Active</dd>
</dl>

http://www.w3.org/TR/html401/struct/lists.html#h-10.3 - Definition lists, created using the DL element, generally consist of a series of term/definition pairs (although definition lists may have other applications).

However, just because you want bold formatting doesn't mean you are restricted to <strong> or <b>. You can use the non-semantic <span> and simply apply the formatting with CSS.

In addition, you can use CSS to add the colons, rather than putting them in your markup:

dt:after { content:":"; }

Perhaps to help clear up some confusion about it's proper usage, it looks like HTML5 will be referring to this tag as a description list.

http://www.w3.org/TR/html5/grouping-content.html#the-dl-element - The dl element represents an association list consisting of zero or more name-value groups (a description list).

这篇关于HTML:表单之外的“标签”的最佳标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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