HTML5中的ID和类属性 [英] ID and class attributes in HTML5

查看:99
本文介绍了HTML5中的ID和类属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在HTML5中id属性更优雅是在某些页面写的。如果我使用类属性而不是id,它是否符合HTML5?感谢您的帮助。

"The id attribute got more classy in HTML5" is written at some pages. If I use class attribute instead of id, does it conform to HTML5? Thanks for your help.

推荐答案

我相信你在谈论本文。嗯,没有什么真的改变 - class es和 id 使用与HTML4中相同的方式。

I believe you're talking about this article. Well, nothing has really changed — classes and ids are used the same way as in HTML4.

除了一件事:HTML4规范说下面的

Except one thing: The HTML4 spec says the following


ID和NAME令牌必须以字母([A-Za-z])开头,并且可以是
后跟任意数量的字母,数字([0-9]),连字符( - ),
下划线(_),冒号(:)和句点(。)。

ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").

id 的要求不那么严格


值必须是唯一的在元素的home
子树的所有ID中,并且必须包含至少一个字符。值不能
包含任何空格字符。

The value must be unique amongst all the IDs in the element’s home subtree and must contain at least one character. The value must not contain any space characters.

因此HTML5 id 可以接受更多字符,这是您要引荐的文章在讨论的内容。

So HTML5 ids can accept more characters, which is what the article you're reffering to is talking about.

这篇关于HTML5中的ID和类属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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