ID选择器:重复的选择器 [英] ID selectors: duplicated selectors

查看:282
本文介绍了ID选择器:重复的选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自< URL: http:// www.w3.org/TR/CSS21/selector.html#id-selectors >


我找到以下文字:

" ; ID类型属性的特殊之处在于没有两个这样的属性

可以具有相同的值; ...


在第二个例子中,我找到了规则:


* #z98y {letter-spacing:0.3em}


在我看来,使用通用选择器这个例子是错误的,

给出上面的文字,其中包括没有两个这样的属性可以具有

相同的值。


鉴于我所访问的所有UA都对待所有重复的ID

在上面的例子中完全相同,我只是好奇UA

是什么*假设*要做。


Sue

From <URL: http://www.w3.org/TR/CSS21/selector.html#id-selectors >

I find the following text:
"What makes attributes of type ID special is that no two such attributes
can have the same value;..."

In the second example, I find the rule:

*#z98y { letter-spacing: 0.3em }

It seems to me that using the universal selector in this example is wrong,
given the text above which includes "no two such attributes can have the
same value".

Given that all of the UAs to which I have access treat all duplicated IDs
in the above example exactly the same, I was just curious about what a UA
is *supposed* to do.

Sue

推荐答案

Sue Sims< su*@css.nu> ;在新闻中写道:op ************** @ netnews.att.net:
Sue Sims <su*@css.nu> wrote in news:op**************@netnews.att.net:
来自< URL: http://www.w3.org/TR/CSS21/selector.html#id - 选择器>

我找到以下文字:
是什么让ID特殊属性的特点是没有两个这样的属性可以具有相同的值; ..."

在第二个例子中,我找到了规则:

*#z98y {letter-spacing:0.3em}
在我看来,在这个例子中使用通用选择器是错误的,因为上面的文字包括没有两个这样的属性可以
具有相同的值。
From <URL: http://www.w3.org/TR/CSS21/selector.html#id-selectors >

I find the following text:
"What makes attributes of type ID special is that no two such
attributes can have the same value;..."

In the second example, I find the rule:

*#z98y { letter-spacing: 0.3em }

It seems to me that using the universal selector in this example is
wrong, given the text above which includes "no two such attributes can
have the same value".



实际上,那里的通用选择器只是意味着什么元素*类型*具有特定ID并不重要

;它可以是< p>,或者< div>,

或者你有什么。选择器引用具有该ID的任何元素。

事实上,文档中只有一个*元素*可以有一个特定的想法

并不意味着只有一个*元素类型*可以拥有它。它可以是任何类型的

元素;

同一份文件中不能有两个或两个以上这样的元素。



Actually, the universal selector there simply means that it doesn''t matter
what element *type* has the particular ID; it could be a <p>, or a <div>,
or what have you. The selector refers to any element with that ID. The
fact that only one *element* in a document can have a particular idea
doesn''t imply that only one *element type* can have it. It could be an
element of any type; there just can''t be two or more such elements in the
same document.


2003年11月17日17:28:19 GMT ,Eric Bohlman< eb ****** @ earthlink.net>写道:
On 17 Nov 2003 17:28:19 GMT, Eric Bohlman <eb******@earthlink.net> wrote:
实际上,通用选择器只是意味着它并不重要
什么元素*类型*具有特定的ID;它可以是< p>,或者< div>,
或者你有什么。选择器引用具有该ID的任何元素。事实上,文档中只有一个*元素*可以有一个特定的想法
并不意味着只有一个*元素类型*可以拥有它。它可以是任何类型的元素;
同一文档中不能有两个或更多这样的元素。
Actually, the universal selector there simply means that it doesn''t
matter
what element *type* has the particular ID; it could be a <p>, or a <div>,
or what have you. The selector refers to any element with that ID. The
fact that only one *element* in a document can have a particular idea
doesn''t imply that only one *element type* can have it. It could be an
element of any type; there just can''t be two or more such elements in the
same document.




在我看来,在该测试用例中使用通用选择器将

鼓励重新使用该ID,这不是允许的。


无论如何,我想知道是否有任何UA不允许这种重复使用?我已经在这里放了一个TC< URL: http://css.nu/examples/1692.html >在重复元素的W3C示例中重新使用

标记,并且会欣赏

输入。这是UA应该如何呈现标记吗?如果是这样,为什么?


苏试图清除Opera bug跟踪系统中的旧错误 Sims



It seemed to me that using the universal selector in that test case would
encourage re-use of the ID, which is not "allowed".

At any rate, I''m wondering whether any UA does not allow this re-use? I''ve
put up a TC here <URL: http://css.nu/examples/1692.html > which re-uses
the markup in the W3C example on duplicated elements, and would appreciate
input. Is this how the UA is supposed to render the markup? If so, why?

Sue "trying to clean out old bugs from the Opera bug tracking system" Sims


Sue Sims写道:
Sue Sims wrote:
2003年11月17日17:28:19 GMT,Eric Bohlman< eb ****** @ earthlink.net>写道:
On 17 Nov 2003 17:28:19 GMT, Eric Bohlman <eb******@earthlink.net> wrote:
实际上,通用选择器只是意味着它并不重要
什么元素*类型*具有特定的ID;它可以是< p>,或者< div>,
或者你有什么。选择器引用具有该ID的任何元素。事实上,文档中只有一个*元素*可以有一个特定的想法
并不意味着只有一个*元素类型*可以拥有它。它可以是任何类型的元素;
同一文档中不能有两个或更多这样的元素。
Actually, the universal selector there simply means that it doesn''t
matter
what element *type* has the particular ID; it could be a <p>, or a <div>,
or what have you. The selector refers to any element with that ID. The
fact that only one *element* in a document can have a particular idea
doesn''t imply that only one *element type* can have it. It could be an
element of any type; there just can''t be two or more such elements in the
same document.



在我看来,在该测试用例中使用通用选择器
会鼓励重复使用身份证,这不是允许的。

无论如何,我想知道是否有任何UA不允许再次使用?
我'这里有一个TC< URL: http://css.nu/ examples / 1692.html >它重复使用W3C示例中的重复元素标记,并且会欣赏输入。这是UA应该如何呈现标记吗?
如果是这样,为什么?

Sue试图清除Opera bug跟踪系统中的旧bug模拟人生


It seemed to me that using the universal selector in that test case
would encourage re-use of the ID, which is not "allowed".

At any rate, I''m wondering whether any UA does not allow this re-use?
I''ve put up a TC here <URL: http://css.nu/examples/1692.html > which
re-uses the markup in the W3C example on duplicated elements, and would
appreciate input. Is this how the UA is supposed to render the markup?
If so, why?

Sue "trying to clean out old bugs from the Opera bug tracking system" Sims



也可以像这样指出一个ID:


< a href ="#blah"> blah< / a>


< h1> id =" blah"> blah< / a>


使用javascript 也可以使用ID:


document.getElementById(''blah'')。style.backgroundCo lor =" green";


因此它也必须是唯一的。如果你不想要那一切。并且只需要

想要使用class属性设置2个元素,这几乎所有元素都允许使用




-

Anne van Kesteren

< http://www.annevankesteren.nl/>


An ID can also be used to be pointed at like this:

<a href="#blah">blah</a>

<h1> id="blah">blah</a>

An ID can also be used to be reached with javascript:

document.getElementById(''blah'').style.backgroundCo lor = "green";

Therefore it also must be unique. If you don''t want all that. And just
want 2 elements be styled the same use the class attribute, which is
also allowed on almost all elements.

--
Anne van Kesteren
<http://www.annevankesteren.nl/>


这篇关于ID选择器:重复的选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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