使用fieldset标签有什么优点?
使用
我实在不明白它是做什么用的。
What are the advantages of using the <fieldset>
tag?
I don't really get what it is used for.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
使用
我实在不明白它是做什么用的。
What are the advantages of using the <fieldset>
tag?
I don't really get what it is used for.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
表单通常分为不同的字段集。
字段集标签允许您对字段集进行逻辑分组,以便您的表单更具描述性。
您还会注意到,您可以使用字段集来设计表单的样式并显示字段之间的逻辑关联。
就像您在“真实”世界中找到的形式一样。
使用字段集的“优点”是它们允许您以最可用的语义方式标记数据(在本例中为表单)。请考虑将字段放在字段集中比将字段放在 div 中更具描述性。 div 不会告诉您字段之间的关系,而字段集会告诉您存在某种关系。
这与许多新的 HTML5 标记集的原理类似。例如,与模糊的
相比,
Forms are often broken up into various sets of fields.
The fieldset tag allows you to logically group sets of fields in order that your forms be more descriptive.
You'll also note that you can use the fieldset to style your forms and display those logical associations between fields.
Just like forms you find in the "real" world.
The "advantages" of using a fieldset are that they allow you to mark up your data (in this case a form) in the most semantic way available. Consider that placing your fields in a fieldset is more descriptive than placing your fields in a div. The div tells you nothing about the relationship between the fields, a fieldset tells you there is a relationship.
It's a similar principle to many of the new HTML5 tagsets.
<footer>
for example tells you more about the meaning of the data inside it compared to an ambiguous<div>
.如果您查看面向开发人员的 HTML5 规范:
http://developers.whatwg.org/forms.html#the-fieldset-element
(如果您点击链接,会有更多信息)
与
legend
元素,它可以让你轻松地做到这一点,如果不使用fieldset
/legend
很难重新创建:<图片src="https://i.sstatic.net/wQ8s2.png" alt="">
If you take a look at the HTML5 spec for Developers:
http://developers.whatwg.org/forms.html#the-fieldset-element
(there's a lot more information if you follow the link)
Combined with the
legend
element, it allows you to easily do this, which is difficult to recreate without usingfieldset
/legend
:它允许您对一组相关字段进行分组并为它们提供图例。
It allows you to group a set of related fields and give them a legend.
你将东西与它组合在一起。如果您需要通过 CSS 或 JavaScript 访问其中的内容,并且不想经历为所有内容分配 ID 的麻烦,那么这会很有用。
而且,传说看起来也不错。
You group stuff together with it. Which is useful if you need to access things in it for CSS or JavaScript, and don't want to go through the hassle of assigning ID's to everything.
Also, the legend looks pretty good.