By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,445 Members | 1,160 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,445 IT Pros & Developers. It's quick & easy.

ID selectors: duplicated selectors

P: n/a
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
Jul 20 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a
Sue Sims <su*@css.nu> wrote in news:op**************@netnews.att.net:
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".


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.
Jul 20 '05 #2

P: n/a
On 17 Nov 2003 17:28:19 GMT, Eric Bohlman <eb******@earthlink.net> wrote:
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.


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
Jul 20 '05 #3

P: n/a
Sue Sims wrote:
On 17 Nov 2003 17:28:19 GMT, Eric Bohlman <eb******@earthlink.net> wrote:
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.

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

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/>
Jul 20 '05 #4

P: n/a
On Mon, 17 Nov 2003 20:30:42 +0100, Anne van Kesteren
<ma**@annevankesteren.nl> wrote:

....<URL: http://css.nu/examples/1692.html >
....
An ID can also be used to be reached with javascript:

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

Thanks! I modified the TC to include the Javascript. It works as expected
on all the browsers I tested...except that the original ID rule is still
applied to *all* of the duplicates.

I would have thought (hoped) that, like the JavaScript is *only* applied
to the first instance, the markup in the rule:

*#z98y { letter-spacing: 0.3em }

would also be applied to only the first instance.

I'm still hoping that someone can explain why is is applied to _every_
instance.

Alan? Yucca? Steve? Anyone?

Sue
Jul 20 '05 #5

P: n/a
Sue Sims wrote:
[snip]
I find the following text:
"What makes attributes of type ID special is that no two such attributes
can have the same value;..." [snip] 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


Since there aren't "supposed" to be multiple elements with the same ID
in the first place, I don't think it's really meaningful to talk about
what UAs are "supposed" to do if there are - except possibly to reject
the document, but that wouldn't be very useful in the real world except
in a validating parser.

Jul 20 '05 #6

P: n/a
On Mon, 17 Nov 2003 21:49:19 +0000, David Leverton <u0*****@abdn.ac.uk>
wrote:

Since there aren't "supposed" to be multiple elements with the same ID
in the first place, I don't think it's really meaningful to talk about
what UAs are "supposed" to do if there are - except possibly to reject
the document, but that wouldn't be very useful in the real world except
in a validating parser.


Or as, in my specific case, trying to decide whether the behavior is a bug
or not. I would expect that an HTML parser would apply the rule to the
first instance of the ID, and show all of the other instances as the
"default". However, that is not the case, *except* in the Javascript that
I applied.

So, I'm no better off that when I asked the original question.

Sue "off to change the TC to xml" Sims
Jul 20 '05 #7

P: n/a
> Or as, in my specific case, trying to decide whether the behavior is
a bug
or not. I would expect that an HTML parser would apply the rule to the first instance of the ID, and show all of the other instances as the
"default".
I would expect that, unless it had some particular interest in error
reporting, an HTML parser might not even bother to check whether there
was an id had already been used and so apply the rule to all
instances. Even if it did discover a reused id I'd consider it quite
reasonable to retain it for rendering purposes. There is no correct
interpretation as the page is invalid.
However, that is not the case, *except* in the Javascript that I applied.


Apples and oranges. The CSS rule matches all the elements with that
id. The JavaScript requests just one of them then acts on that one
alone(it seems natural that the first one is returned though I could
well imagine the behaviour isn't defined for cases where there is more
than one). You haven't asked it do anything with the other ones.

Jul 20 '05 #8

P: n/a
On Mon, 17 Nov 2003 20:27:17 GMT, Sue Sims <su*@css.nu> wrote:
On Mon, 17 Nov 2003 20:30:42 +0100, Anne van Kesteren
<ma**@annevankesteren.nl> wrote:

...<URL: http://css.nu/examples/1692.html >
...
An ID can also be used to be reached with javascript: document.getElementById('blah').style.backgroundCo lor = "green";

Thanks! I modified the TC to include the Javascript. It works as
expected on all the browsers I tested...except that the original ID rule
is still applied to *all* of the duplicates.


Why do this testing anyway? It seems to me that you're looking for a way
to use the Id for something it was not meant to.
I would have thought (hoped) that, like the JavaScript is *only* applied
to the first instance, the markup in the rule:

*#z98y { letter-spacing: 0.3em }

would also be applied to only the first instance.
Forget it. If you want it to apply to the first instance, then let the
elements share a classname that you use to apply formatting to all the
elements, and a unique id for each of the elements that you use when
you apply formatting to that single element.
I'm still hoping that someone can explain why is is applied to _every_
instance.


Let me quote the CSS 2.1 specification which is pretty clear at this point:
<URL: http://www.w3.org/TR/CSS21/selector.html>

E#myid Matches any E element with ID equal to "myid".

--
Ole Kristian Bangås
Jul 20 '05 #9

P: n/a
In article <op**************@netnews.att.net> in
comp.infosystems.www.authoring.stylesheets, Sue Sims <su*@css.nu>
wrote:
*#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".


I'd say redundant rather than wrong. Unless I'm mistaken, that
selector is the same as "#z98y".

--
Stan Brown, Oak Road Systems, Cortland County, New York, USA
http://OakRoadSystems.com/
HTML 4.01 spec: http://www.w3.org/TR/html401/
validator: http://validator.w3.org/
CSS 2 spec: http://www.w3.org/TR/REC-CSS2/
2.1 changes: http://www.w3.org/TR/CSS21/changes.html
validator: http://jigsaw.w3.org/css-validator/
Jul 20 '05 #10

P: n/a
Stan Brown wrote:
In article <op**************@netnews.att.net> in
comp.infosystems.www.authoring.stylesheets, Sue Sims <su*@css.nu>
wrote:
*#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".

I'd say redundant rather than wrong. Unless I'm mistaken, that
selector is the same as "#z98y".

It is the example used by the W3C:
<http://www.w3.org/TR/CSS21/selector.html#id-selectors>. You can also
find it in the CSS3 Selectors draft.

--
Anne van Kesteren
<http://www.annevankesteren.nl/>
Jul 20 '05 #11

P: n/a
Stan Brown wrote:
In article <op**************@netnews.att.net> in
comp.infosystems.www.authoring.stylesheets, Sue Sims <su*@css.nu>
wrote:
*#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".

I'd say redundant rather than wrong. Unless I'm mistaken, that
selector is the same as "#z98y".


Unless you've defined a default namespace with the CSS3 "@namespace"
rule, in which case it only applies to elements in that namespace.

Jul 20 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.