473,546 Members | 2,644 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ID selectors: duplicated selectors

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
11 2193
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
On 17 Nov 2003 17:28:19 GMT, Eric Bohlman <eb******@earth link.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
Sue Sims wrote:
On 17 Nov 2003 17:28:19 GMT, Eric Bohlman <eb******@earth link.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">bl ah</a>

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

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

document.getEle mentById('blah' ).style.backgro undColor = "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.annevankest eren.nl/>
Jul 20 '05 #4
On Mon, 17 Nov 2003 20:30:42 +0100, Anne van Kesteren
<ma**@annevanke steren.nl> wrote:

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

document.getEle mentById('blah' ).style.backgro undColor = "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
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
On Mon, 17 Nov 2003 21:49:19 +0000, David Leverton <u0*****@abdn.a c.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
> 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
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**@annevanke steren.nl> wrote:

...<URL: http://css.nu/examples/1692.html >
...
An ID can also be used to be reached with javascript: document.getEle mentById('blah' ).style.backgro undColor = "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
In article <op************ **@netnews.att. net> in
comp.infosystem s.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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2613
by: Tony Benham | last post by:
I have been getting to grips with css recently (very slowly), and one area I have a problem is when to use class selectors or id selectors. Are there any guidelines when to use each type ? The key difference is, AFAICS, is that id selectors can only be used once, whereas class selectors can be used repeatedly ? Is this the main differentiator...
18
2096
by: news.pandora.be | last post by:
I tried everything. I even tested it in combination with opera and mozilla. (I use IE 6 mostly) It's reduced to the simple example below. Please tell me what is wrong with my understaning of child selectors! I realy dont know :( <html> <head> <style>
4
4241
by: Andy Fish | last post by:
hi, I am using descendent selectors to format cells within a table according to the css class of the table. However, when using nested tables, it seems to pick up the outer matching rule rather than the inner one. here's a self-contained example: <HTML><HEAD> <style type="text/css"> table.foo td { background-color:red; }
7
1568
by: Biguana | last post by:
Hi, Apologies in advance for a newbie question, but I'm trying to decipher css stuff, I can't find a direct parallel in web tutorials, and I'm not sure what to search on. My problem is that I'm familiar with multiple selectors (and various types of selectors) but what does it mean if they are arranged like this? :
6
1884
by: Rhino | last post by:
What's the simplest way to determine which, if any, of my selectors are not needed in a given stylesheet? I have a small number of HTML pages that share two stylesheets; one stylesheet is for display purposes and one is for printing. I suspect that some of the selectors in my stylesheet are no longer needed due to deletions of parts of the...
7
4291
by: Dan | last post by:
Hi, IE 7 does not seem to like child selectors for lists. I couldn't find anything addressing this with google search. Example of problem-- If I want to apply the color red to all ordered list child <liitems within unordered lists, it seems I need to do the following depending on the browser in which I want it to work: Firefox (works as...
6
1636
by: Ryan Liu | last post by:
Hi, If I have tens of thousands DataRow in a DataTable and allow the end user to pick any DataColumn(s) to check for duplicated lines, the data is so large, is there a better API, algorithm can be used for this purpose? Thanks a lot! Ryan
7
2664
by: John Dann | last post by:
I'm unclear as to how best to use what I'm terming the top-level CSS selectors, by which I mean selectors like *, html and body. I'm coming at this from trying to understand how best to set font sizes but I seem to have strayed into a broader question. Some CSS guides seem to suggest that a * declaration is good practice for any style...
5
1743
by: Nathan Sokalski | last post by:
I'm not sure if this is the right place to ask this question, but I wasn't sure where else to go. I have a table made of the following tags: <table class="myclass"> <tbody> <tr><td>.</td></tr> <tr><td>.</td></tr> <tr><td>.</td></tr> </tbody> </table>
0
7504
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7694
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7947
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7461
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6026
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3491
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3470
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1046
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
747
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.