为什么在CSS中,#1(作为div元素的ID)样式不起作用? [英] Why in CSS, #1 (as id of a div element) styling doesn't work?

查看:56
本文介绍了为什么在CSS中,#1(作为div元素的ID)样式不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<div class="image" id="1"></div>
<div class="image" id="2"></div>
<div class="image" id="3"></div>

http://codepen.io/Chrez/pen/KdWrBe

如您在Codepen中所见,"id ='1'"的样式无效.

As you see in the codepen the styling of "id='1'" doesn't work.

我需要它,因为它是用于滑块的,而我的jQuery函数是这样工作的.

I need it this way because it's for slider, and my jQuery functions work this way.

推荐答案

它的CSS规则是,不能将Number用作起始字符或类或id.这就是为什么它不起作用的原因.您至少必须在数字前加上1个字母!

Its CSS's rule that you can't use Number as starting character or a class or id. That is why it wont work. You at least have to put 1 alphabet before the number!

这是w3c中所说的-

在CSS中,标识符(包括选择器中的元素名称,类和ID)只能包含字符[a-zA-Z0-9]和ISO 10646字符U + 00A0及更高版本,以及连字符(-)和下划线(_);它们不能以一个数字,两个连字符或一个连字符后跟一个数字开头.标识符还可以包含转义字符和任何ISO 10646字符作为数字代码(请参阅下一项).例如,标识符"B& W?"可以写成"B \& W \?"或"B \ 26 W \ 3F".

In CSS, identifiers (including element names, classes, and IDs in selectors) can contain only the characters [a-zA-Z0-9] and ISO 10646 characters U+00A0 and higher, plus the hyphen (-) and the underscore (_); they cannot start with a digit, two hyphens, or a hyphen followed by a digit. Identifiers can also contain escaped characters and any ISO 10646 character as a numeric code (see next item). For instance, the identifier "B&W?" may be written as "B\&W\?" or "B\26 W\3F".

http://www.w3.org/TR/CSS21/syndata.html#characters

这篇关于为什么在CSS中,#1(作为div元素的ID)样式不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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