对于表单字段提示/注释来说,语义上最正确的 HTML 元素是什么?
标签和字段都很简单;我们有 ,然后是相关的输入字段。但是,对于该字段下的较小信息文本来说,语义上最正确的 HTML 元素是什么?
The label and the field are easy; we have <label>
and then the relevant input field. But what is the most semantically-correct HTML element to use for the smaller informational text that goes under the field?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道连接它们的特定元素或属性,但您可以使用 ARIA 属性
aria-scribedby
来实现:但将所有内容包含在
label
中似乎不错对我来说(也提供了良好的样式能力,因为你有一个语义容器):或者你甚至可以混合两者。
另一种方法可能是将描述放在
input
元素的title
(或 @Alohci 建议的placeholder
)属性中(语义上这是描述它的那个),但在这种情况下,您必须通过 Javascript 将其插入标记(或使用input:after { content : "eg " attr(placeholder) }
- 由 @Alohci 建议的 CSS )。I don't know of a specific element or attribute to connect them, but you can do so using the ARIA attribute
aria-describedby
:But including everything in the
label
seems good to me either (also gives good styling abilities, as you have a - semantic - container):Or you could even mix the two.
Another approach could be to put the description in the
title
(orplaceholder
as suggested by @Alohci) attribute of theinput
element (semantically this is the one describing it), but in this case you have to insert it to the markup through Javascript (or CSS usinginput:after { content : "e.g. " attr(placeholder) }
- suggested by @Alohci).