Class attribute values

P

Patient Guy

While the values of 'id' and 'name' attributes include restrictions on the
use of characters such as beginning with a letter, the values of the
'class' attribute define no restriction as I can find.

Thus the use of:

class="thumbedImage 0.4"

is permitted, and could be used as an attribute in IMG elements to identify
images whose sizes I want to change dynamically with the loading of the
document body through a script function call, as the "onload" attribute is
not allowed for IMG elements in the specification.
(The script function essentially would get a list of image element nodes
from the document body, examine the class attribute values for the presence
of the correct values, and then make changes to those images having the
required values.)

Is there anyone whose understanding of the specification differs from this
understanding?
 
S

Spartanicus

Patient Guy said:
While the values of 'id' and 'name' attributes include restrictions on the
use of characters such as beginning with a letter, the values of the
'class' attribute define no restriction as I can find.

Thus the use of:

class="thumbedImage 0.4"

is permitted,

The above assigns two classes to the element, "thumbedImage" and "0.4",
the latter is not permitted since class names are not allowed to start
with a digit: http://www.w3.org/TR/CSS21/syndata.html#q6
 
S

Stephen Poley

While the values of 'id' and 'name' attributes include restrictions on the
use of characters such as beginning with a letter, the values of the
'class' attribute define no restriction as I can find.

Thus the use of:

class="thumbedImage 0.4"

is permitted, and could be used as an attribute in IMG elements to identify
images whose sizes I want to change dynamically with the loading of the
document body through a script function call, as the "onload" attribute is
not allowed for IMG elements in the specification. ....
Is there anyone whose understanding of the specification differs from this
understanding?


Well, I couldn't immediately find something prohibiting that. However:

class="thumbedImage 0.4" assigns the classes "thumbedImage" and "0.4"
to the element.

In CSS, img.0.4 { ... } would refer to images having the class 0 and
the class 4.

In fact in CSS: "identifiers (including element names, classes, and IDs
in selectors) can contain only the characters [A-Za-z0-9] and ISO 10646
characters 161 and higher, plus the hyphen (-); they cannot start with a
hyphen or a digit."

Even if you can use periods in HTML class-names, it seems to me that it
would be inadvisable.
 
T

Toby Inkster

Spartanicus said:
The above assigns two classes to the element, "thumbedImage" and "0.4",
the latter is not permitted since class names are not allowed to start
with a digit: http://www.w3.org/TR/CSS21/syndata.html#q6

In HTML, class names *are* allowed to start with a digit. However, if you
choose to use class names that start with a digit, you can't select them
using the CSS "dot-class" selector -- that is classes that don't start
with a letter aren't particularly useful for styling, but can be used for
general purpose element subclassing.)

(Of course you can select them in CSS using *[class~="0.4"], though
browser support for this syntax is less widespread.)
 
S

Spartanicus

Toby Inkster said:
In HTML, class names *are* allowed to start with a digit.

You're almost clever. Had you been really clever you might have noticed
that I didn't mention HTML and referenced the CSS rules.
 
T

Toby Inkster

Spartanicus said:
You're almost clever. Had you been really clever you might have noticed
that I didn't mention HTML and referenced the CSS rules.

What I *did* notice was that the post to which you were replying gave
an HTML (not CSS) example, and didn't mention CSS at all.
 
D

David Dorward

Spartanicus said:
You're almost clever. Had you been really clever you might have noticed
that I didn't mention HTML and referenced the CSS rules.

And had you been really clever you might have noticed that this is
ciwa.*html*, that the context of the question was HTML and JavaScript, and
that, as Toby pointed out, you can reference classes that start with a
number in CSS - you just have to do so via an attribute selector.
 
J

Jan Roland Eriksson

You're almost clever. Had you been really clever you might have noticed
that I didn't mention HTML and referenced the CSS rules.

Now my dear Spartanicus, you are just plain dumb; go put on your white
"dumb ass" cone hat and sit tight in a corner with that one on for the
coming 24 hours.
 
S

Spartanicus

Toby Inkster said:
What I *did* notice was that the post to which you were replying gave
an HTML (not CSS) example, and didn't mention CSS at all.

So it did, apologies for my remark.
 
S

Spartanicus

David Dorward said:
And had you been really clever you might have noticed that this is
ciwa.*html*

And alt.html (where it shows up here). Btw, I undid your attempt to
remove alt.html from this thread.
, that the context of the question was HTML and JavaScript,

That I indeed missed.
and
that, as Toby pointed out, you can reference classes that start with a
number in CSS - you just have to do so via an attribute selector.

That doesn't change the fact that class names cannot start with a digit
according to the CSS syntax rules.
 
N

Neredbojias

With neither quill nor qualm, Jan Roland Eriksson quothed:
Now my dear Spartanicus, you are just plain dumb; go put on your white
"dumb ass" cone hat and sit tight in a corner with that one on for the
coming 24 hours.

Hah, what do you know? "Dumb ass hats" don't come in white. However,
"dunce caps" may be procured in a light eggshell.
 
N

Neredbojias

With neither quill nor qualm, Spartanicus quothed:

....
That doesn't change the fact that class names cannot start with a digit
according to the CSS syntax rules.

And that, as far as I'm concerned, was the main point.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top