html id / class第一个符号数字,是否有效? [英] html id/class first symbol digit, is valid?

查看:561
本文介绍了html id / class第一个符号数字,是否有效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在HTML中,哪些字符作为 id class 属性中的第一个字符有效?



例如,是< div id =4bla>< / div> 有效或必须以只有字母?

解决方案

HTML5:

在HTML5中,使用数字开始ID确实是有效的。



在HTML5中,即使这是有效的:

 < p id =#> Foo。 
< p id =##>条。
< p id =♥> Baz。
< p id =©> Inga。
< p id ={}> Lorem。

就像你的例子:

 < div id =4bla>< / div> 

注意:它可能在HTML5中有效,但它在CSS中无效
$ b 这意味着< div id =4bla>< / div> 是有效的, code>#4bla {background-color:red;



开始使用字符代替最大兼容性。



HTML4:



如果您仍在使用HTML4,则无效:


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


In HTML, what characters are valid as the first character in an id or class attribute?

For example, is <div id="4bla"></div> valid or must they start with only letters?

解决方案

HTML5:

As of HTML5, it is indeed valid to start an ID with a digit.

In HTML5, even this is valid:

<p id="#">Foo.
<p id="##">Bar.
<p id="♥">Baz.
<p id="©">Inga.
<p id="{}">Lorem.

As is your example:

<div id="4bla"></div>

Note: It may be valid in HTML5, however it is not valid in CSS.

That means <div id="4bla"></div> is valid, but #4bla { background-color:red; } isn't.

Start ID's with characters instead for maximum compatibility.

HTML4:

It is invalid if you're still using HTML4:

"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 (".")."

这篇关于html id / class第一个符号数字,是否有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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