This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > Stylesheets > September 2004 > Re: CSS ID Class selectors





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Re: CSS ID Class selectors
Harlan Messinger

2004-09-14, 7:17 pm


"Virginia Grieco" <vgrieco@optonline.net> wrote in message
news:zSA1d.1594$4p6.1079777@news4.srv.hcvlny.cv.net...
> Can anyone give me an example of what a Class ID selector would be used

for?
>
> I am fairly new to CSS, and I understand that ID selectors can only be

used
> once within a website.


In HTML, the value of an ID *attribute* must be unique within a web *page*.
This is independent of whether any styles are defined in CSS for a selector
that references a particular ID.

There are at least *three* reasons to specify an ID attribute for an element
on a web page:

1. As a hook for applying styles.

2. As a means of referencing elements in client-side code.

3. As a target for an internal hyperlink such as <a href="#thisplace">.

Suppose you have a set of styles that should apply to paragraphs, lists,
hyperlinks, and so forth, only within a footnote section that appears on
your web pages. Give an ID to the footnote section or whatever, and then use
selectors based on the ID.

p { /* usual properties you want on your web pages */ }
li { /* usual properties you want on your web pages */ }
a { /* usual properties you want on your web pages */ }

#footnotes p { /* properties you want to apply within your footnotes
section /* }
#footnotes li { /* properties you want to apply within your footnotes
section /* }
#footnotes a { /* properties you want to apply within your footnotes
section /* }

...
<div id="footnotes">
<!-- Footnotes go here -->
</div>

Jan Roland Eriksson

2004-09-15, 12:17 pm

On Tue, 14 Sep 2004 11:43:46 -0400, "Harlan Messinger"
<h.messinger@comcast.net> wrote:

>
>"Virginia Grieco" <vgrieco@optonline.net> wrote in message
>news:zSA1d.1594$4p6.1079777@news4.srv.hcvlny.cv.net...
>for?

[...]
>In HTML, the value of an ID *attribute*...


Well; formally speaking ID is _not_ an element attribute...

--
Rex


Harlan Messinger

2004-09-15, 12:17 pm

Jan Roland Eriksson <jrexon@newsguy.com> wrote:

>On Tue, 14 Sep 2004 11:43:46 -0400, "Harlan Messinger"
><h.messinger@comcast.net> wrote:
>
>[...]
>
>Well; formally speaking ID is _not_ an element attribute...


Why would you say that? Besides the fact that it has all the qualities
of an attribute, which ought to be sufficient basis for contradicting
you, the spec calls it an attribute, so how much more formally spoken
does it need to be?

http://www.w3.org/TR/html4/struct/global.html#h-7.5.2

"7.5.2 Element identifiers: the id and class attributes
Attribute definitions

id = name [CS]
This attribute assigns a name to an element. This name must be unique
in a document...."


--
Harlan Messinger
Remove the first dot from my e-mail address.
Veuillez ๔ter le premier point de mon adresse de courriel.
Jan Roland Eriksson

2004-09-15, 7:18 pm

On Wed, 15 Sep 2004 09:30:54 -0400, Harlan Messinger
<hmessinger.removethis@comcast.net> wrote:

>Jan Roland Eriksson <jrexon@newsguy.com> wrote:
>
[color=darkred]
[color=darkred]
[color=darkred]
>Why would you say that?


Yea, that's a good question.

Allow me to switch on my brain before I continue to say that what I was
aiming at is the fact that there is a difference in what type of data
you can assign as a value for an ID as compared to most other
attributes.

An ID can only be assigned an ID value which in practice means that it
can only be a fully qualified SGML name starting with a valid name_start
character and optionally followed only by valid name_characters.

At the other side we have the vast majority of HTML element attributes
that takes on values that boils down to be of type CDATA. Very few HTML
attribute values can actually be checked for validity, if one wanted to
do that, since the attribute values are never parsed.

ID values otoh are always parsed.

--
Rex


Harlan Messinger

2004-09-15, 7:18 pm

Jan Roland Eriksson <jrexon@newsguy.com> wrote:

>On Wed, 15 Sep 2004 09:30:54 -0400, Harlan Messinger
><hmessinger.removethis@comcast.net> wrote:
>
>
>
>
>
>Yea, that's a good question.
>
>Allow me to switch on my brain before I continue to say that what I was
>aiming at is the fact that there is a difference in what type of data
>you can assign as a value for an ID as compared to most other
>attributes.
>
>An ID can only be assigned an ID value which in practice means that it
>can only be a fully qualified SGML name starting with a valid name_start
>character and optionally followed only by valid name_characters.
>
>At the other side we have the vast majority of HTML element attributes
>that takes on values that boils down to be of type CDATA. Very few HTML
>attribute values can actually be checked for validity, if one wanted to
>do that, since the attribute values are never parsed.
>
>ID values otoh are always parsed.


But "attribute" doesn't mean "property whose range of legal values is
limited" or "property whose value needs to be or can be validated
syntatically or semantically". Some attributes' values are restricted
and some aren't, that's all. So while your latest observations are
correct, they have no bearing on the correctness of my having referred
to ID as an attribute.


--
Harlan Messinger
Remove the first dot from my e-mail address.
Veuillez ๔ter le premier point de mon adresse de courriel.
Jan Roland Eriksson

2004-09-15, 11:53 pm

On Wed, 15 Sep 2004 13:39:07 -0400, Harlan Messinger
<hmessinger.removethis@comcast.net> wrote:

>Jan Roland Eriksson <jrexon@newsguy.com> wrote:

[...]
[...][color=darkred]
[...][color=darkred]
[color=darkred]
>But "attribute" doesn't mean "property whose range of legal values is
>limited" or "property whose value needs to be or can be validated
>syntatically or semantically".


The SGML standard is very specific about what constitutes an
'attribute'; from the "Handbook" pg.127...

"attribute (of an element): A characteristic quality,
other than type or content."

For all times of SGML the ID (and also IDCAP, IDLINK, IDREF, IDREFCAP
and IDREFS) has been treated as something special, apart from "normal"
attributes of an element.

The ID family of "attributes" (ID, IDREF and IDREFS) do not really set a
"characteristic quality" for the element where they appear but instead
they serve to provide identifiable points of reference and "hooks" to
points of reference in a document.

>some attributes' values are restricted and some aren't, that's all.


The possible values for 'ID' in HTML is definitely described by a
(ridiculously big, but finite) number. That is not so with CDATA
attributes though, their range of allowed values are infinite.

>So while your latest observations are correct, they have no bearing
>on the correctness of my having referred to ID as an attribute.


If you only want my approval on your use of words I can grant you that
straight off. The "Handbook" lists ID, IDREF and IDREFS as attributes
too, but continues to great length to describe what it is that makes the
ID... family of "attributes" so special.

I'm an old "SGML sod" and I have over the years created quite a number
of "HTML authoring tools" based on the SP suite. Most often I find that
SGMLNORM is my best friend when it comes to production of markup good
enough to put up on a server somewhere.

ID's comes in handy in local processing at times but I have yet to find
that I define a set of ID values for any other purpose than to provide
hooks for linking and cross refs.

Others do use more "modern" approaches as in what came in on
comp.text.sgml just today...

<http://nedron.net/xml-test/fedora-boot-floppy.xml>

....where we can find some solid use of ID's in a 'docbook' document to
create parts of visible content that is gathered from ID'ed elements in
the original markup.

(XSLT capable version of Mozilla is required to view that document)

I'm not at all convinced that the 'TOC' produced on the fly (not part of
the visible markup) in that document could be said to be a
"characteristic quality" of the elements that was IDentified to be used
as a source of that 'TOC'? Correct me if I'm wrong?

--
Rex


Harlan Messinger

2004-09-16, 6:32 am

Jan Roland Eriksson <jrexon@newsguy.com> wrote:

>On Wed, 15 Sep 2004 13:39:07 -0400, Harlan Messinger
><hmessinger.removethis@comcast.net> wrote:
>
>[...]
>[...]
>[...]
>
>
>The SGML standard is very specific about what constitutes an
>'attribute'; from the "Handbook" pg.127...
>
> "attribute (of an element): A characteristic quality,
> other than type or content."
>
>For all times of SGML the ID (and also IDCAP, IDLINK, IDREF, IDREFCAP
>and IDREFS) has been treated as something special, apart from "normal"
>attributes of an element.
>
>The ID family of "attributes" (ID, IDREF and IDREFS) do not really set a
>"characteristic quality" for the element where they appear but instead
>they serve to provide identifiable points of reference and "hooks" to
>points of reference in a document.
>
>
>The possible values for 'ID' in HTML is definitely described by a
>(ridiculously big, but finite) number. That is not so with CDATA
>attributes though, their range of allowed values are infinite.
>
>
>If you only want my approval on your use of words I can grant you that
>straight off. The "Handbook" lists ID, IDREF and IDREFS as attributes
>too, but continues to great length to describe what it is that makes the
>ID... family of "attributes" so special.


What do I want with your approval? I knew I was right and the checking
the official sources confirmed it. The only question in my mind was
why you were continuing to reason why ID shouldn't be called an
attribute. The "specialness" of ID is irrelevant--the definition of
"attribute" isn't contingent on the attribute being non-special--and
the lack of restrictions on its value isn't relevant at all. (By the
way--since when is the ID of an HTML element--we were talking about
HTML, not SGML--not restricted?)

[snipping a bunch of stuff whose relevance eludes me]

--
Harlan Messinger
Remove the first dot from my e-mail address.
Veuillez ๔ter le premier point de mon adresse de courriel.
Jan Roland Eriksson

2004-09-16, 6:32 am

On Thu, 16 Sep 2004 01:11:38 -0400, Harlan Messinger
<hmessinger.removethis@comcast.net> wrote:

>Jan Roland Eriksson <jrexon@newsguy.com> wrote:
>

[...]
[color=darkred]
>...why you were continuing to reason why ID shouldn't be called an
>attribute.


As per ISO8879[1] (the SGML standard) ID is listed among the other
attribute definitions because it's convenient to do so, still the
characteristics of ID (plus IDREF and IDREFS) is so different from other
attribute types that it must receive special treatment.

>The "specialness" of ID is irrelevant...


Nope.

>...and the lack of restrictions on its value isn't relevant at all.


You got that backwards, ID does have restrictions on its value
assignments. Most other attributes as defined in HTML have not[2].

>(By the way--since when is the ID of an HTML element--we were
>talking about HTML, not SGML--not restricted?)


What?

HTML claims to be an application of SGML[3][4], as such HTML is required
to follow all parts of the SGML standard. It is not allowed for HTML to
change the foundation upon which it is built.

[1]<http://www.iso.org/iso/en/Catalogue...?CSNUMBER=16387>
[2]<http://www.htmlhelp.com/reference/html40/attrs.html>
[3]<http://www.w3.org/TR/html4/conform.html#h-4.1>
[4]<http://www.w3.org/TR/html4/sgml/intro.html>

--
Rex


Harlan Messinger

2004-09-17, 12:39 am

Jan Roland Eriksson <jrexon@newsguy.com> wrote:

>On Thu, 16 Sep 2004 01:11:38 -0400, Harlan Messinger
><hmessinger.removethis@comcast.net> wrote:
>
>
>[...]
>
>
>As per ISO8879[1] (the SGML standard) ID is listed among the other
>attribute definitions because it's convenient to do so, still the
>characteristics of ID (plus IDREF and IDREFS) is so different from other
>attribute types that it must receive special treatment.


When a set X is defined as all {x(i)} that have certain
characteristics, there is no implicit proviso "except for those x(i)
that have something else special about them". ID meets the definition
of "attribute", and is on top of it explicitly declared to be one.
There is no precept that justifies, "Oh, but it has other special
properties, so it really isn't an attribute after all."

>
>
>Nope.


The standards say you're wrong.

>
>
>You got that backwards, ID does have restrictions on its value
>assignments. Most other attributes as defined in HTML have not[2].


Correct, I got my wires reversed.


--
Harlan Messinger
Remove the first dot from my e-mail address.
Veuillez ๔ter le premier point de mon adresse de courriel.
Neal

2004-09-17, 11:16 pm

On Tue, 14 Sep 2004 11:46:39 GMT, Virginia Grieco <vgrieco@optonline.net>
wrote:

> Can anyone give me an example of what a Class ID selector would be used
> for?
>
> I am fairly new to CSS, and I understand that ID selectors can only be
> used
> once within a website.


Well, that's not exactly true. An ID is used once within a webpage.
Important difference. I can put id="foo" once on every page in my site. In
fact, I could put it on different elements if I wanted.

A class, though, can be used over and over again. So if it's something
that could happen more than once on a page, use class.

Ids can also be used as linking points where class cannot.

Check out w3schools.com and their HTML + CSS tutorials for more detail.
Virginia Grieco

2004-09-17, 11:16 pm

Can anyone give me an example of what a Class ID selector would be used for?

I am fairly new to CSS, and I understand that ID selectors can only be used
once within a website.

Thanks for your help.

--




Ginny
Student


Jan Roland Eriksson

2004-09-19, 4:16 am

On Wed, 15 Sep 2004 09:30:54 -0400, Harlan Messinger
<hmessinger.removethis@comcast.net> wrote:

>Jan Roland Eriksson <jrexon@newsguy.com> wrote:
>
[color=darkred]
[color=darkred]
[color=darkred]
>Why would you say that?


Yea, that's a good question.

Allow me to switch on my brain before I continue to say that what I was
aiming at is the fact that there is a difference in what type of data
you can assign as a value for an ID as compared to most other
attributes.

An ID can only be assigned an ID value which in practice means that it
can only be a fully qualified SGML name starting with a valid name_start
character and optionally followed only by valid name_characters.

At the other side we have the vast majority of HTML element attributes
that takes on values that boils down to be of type CDATA. Very few HTML
attribute values can actually be checked for validity, if one wanted to
do that, since the attribute values are never parsed.

ID values otoh are always parsed.

--
Rex


Harlan Messinger

2004-09-19, 4:16 am

Jan Roland Eriksson <jrexon@newsguy.com> wrote:

>On Wed, 15 Sep 2004 09:30:54 -0400, Harlan Messinger
><hmessinger.removethis@comcast.net> wrote:
>
>
>
>
>
>Yea, that's a good question.
>
>Allow me to switch on my brain before I continue to say that what I was
>aiming at is the fact that there is a difference in what type of data
>you can assign as a value for an ID as compared to most other
>attributes.
>
>An ID can only be assigned an ID value which in practice means that it
>can only be a fully qualified SGML name starting with a valid name_start
>character and optionally followed only by valid name_characters.
>
>At the other side we have the vast majority of HTML element attributes
>that takes on values that boils down to be of type CDATA. Very few HTML
>attribute values can actually be checked for validity, if one wanted to
>do that, since the attribute values are never parsed.
>
>ID values otoh are always parsed.


But "attribute" doesn't mean "property whose range of legal values is
limited" or "property whose value needs to be or can be validated
syntatically or semantically". Some attributes' values are restricted
and some aren't, that's all. So while your latest observations are
correct, they have no bearing on the correctness of my having referred
to ID as an attribute.


--
Harlan Messinger
Remove the first dot from my e-mail address.
Veuillez ๔ter le premier point de mon adresse de courriel.
Sponsored Links


Copyright 2003 - 2008 forum4designers.com  Software forum  Computer Hardware reviews