为什么要为 HTML 表单而不是表格使用定义列表(DL、DD、DT)标签? [英] Why use definition lists (DL,DD,DT) tags for HTML forms instead of tables?

查看:23
本文介绍了为什么要为 HTML 表单而不是表格使用定义列表(DL、DD、DT)标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近遇到了一些执行以下操作的示例:

I've come across a few examples recently that do things like:

<dl>
  <dt>Full Name:</dt>
  <dd><input type="text" name="fullname"></dd>
  <dt>Email Address:</dt>
  <dd><input type="text" name="email"></dd>
</dl>

用于制作 HTML 表单.这是为什么?与使用表格相比有什么优势?

for doing HTML forms. Why is that? What is the advantage over using tables?

推荐答案

我想这取决于你的语义,但在我看来:

I guess it's up to you to determine the semantics, but in my opinion:

应该使用与表单相关的属性而不是定义列表.

Rather than a definition list, form-related properties should be used.

<form>
  <label for="fullname">Full Name:</label>
  <input type="text" name="fullname" id="fullname">
  <label for="email">Email Address:</label>
  <input type="text" name="email" id="email">
</form>

The "for" attribute in the <label> tag should reference the "id" attribute of a <input> tag. Note that when labels are associated with fields, clicking the label will put the associated field in focus.

您还可以使用像 <fieldset> 这样的标签.将表单的各个部分聚集在一起并为字段集添加标题.

You can also use tags like <fieldset> to cluster sections of a form together and <legend> to caption a fieldset.

这篇关于为什么要为 HTML 表单而不是表格使用定义列表(DL、DD、DT)标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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