为什么要使用< label>? [英] Why use <label>?

查看:115
本文介绍了为什么要使用< label>?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从演示的角度来看,如果我在< label> 标签之间写入文本,它看起来与我没有的文本相同。



那么,为什么我们要使用这个标签呢?

解决方案

HTML是不是关于演示文稿。这是一种描述数据的方式。如果您有一些文本代表输入的标签,则可以将其包装在标签标签中,而不是用于展示,但因为这就是它的原因。没有标签标签,该文本几乎没有意义。使用标签标签及其属性(或不包含*)属性(或不包含*),您将提供含义和结构,并在您的标记之间形成一种关系,以便计算机/解析器/浏览器更好地理解/ people。



*如果您将标签包裹在输入中,您不一定需要



< label>我的输入< input type =textid = my-input/>< / label>

From a presentation perspective, if I write a text between a <label> tag it looks identical as to if I hadn't.

So, why do we use this tag at all?

解决方案

HTML is not about presentation. It is a way of describing data. If you have some text that represents a label for an input, you wrap it in label tags not for presentation but because that's what it is. Without the label tag, that text is almost meaningless. With the label tag and its for attribute (or not*) you are providing meaning and structure and forming a relationship between your markup that can be better understood by computers/parsers/browsers/people.

* you don't necessarily need the for if you wrap the label around the input:

<label>My input
  <input type="text" id="my-input" />
</label>

这篇关于为什么要使用&lt; label&gt;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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