CSS: Class error

  • Thread starter Luigi Donatello Asero
  • Start date
L

Luigi Donatello Asero

What is wrong with this?
..subsubsection#sverige A { background-color: #99ffcc;
background-image:none;
color: #000000; display: block; text-align:center;}

I get a "class error"
 
J

Jimmy

Luigi said:
What is wrong with this?
.subsubsection#sverige A { background-color: #99ffcc;
background-image:none;
color: #000000; display: block; text-align:center;}

I get a "class error"

weird...

try adding a space:

..subsubsection #sverige A

{
background-color: #99ffcc;
background-image:none;
color: #000000;
display: block;
text-align:center;
}
 
L

Luigi Donatello Asero

Els said:
Of course you do.

So, what is it, a class? (.susubsection) an id? (#sverige)?
Can't make the two into a hybrid.


"subsubsection" should be the class and "sverige" the id which belongs to
the class "subsubsection" and which I want to define.
 
E

Els

Luigi said:
"subsubsection" should be the class and "sverige" the id which belongs to
the class "subsubsection" and which I want to define.

Then just use #sverige. There is only one element with id 'sverige' on
the page (I hope!), so the class need not be mentioned.
 
L

Luigi Donatello Asero

Luigi Donatello Asero said:
"subsubsection" should be the class and "sverige" the id which belongs to
the class "subsubsection" and which I want to define.


In theory there could have been another id which is called "sverige" as
well but belongs to a different class, so I guess that it is always safer to
write both the class and the id. The id is a child of the class.
 
E

Els

Luigi said:
In theory there could have been another id which is called "sverige" as

No, in theory[1] there couldn't be. In practice there could be, but it
would be wrong practice.
well but belongs to a different class, so I guess that it is always safer to
write both the class and the id. The id is a child of the class.

If the element with the id is a child of the element with the class,
as in <div class="subsubsection"><p id="sverige">, then write it as
..subsubsection #sverige.

_________
[1] theory based on assumption that you try to follow the W3C
recommendations
 
L

Luigi Donatello Asero

Els said:
Then just use #sverige. There is only one element with id 'sverige' on
the page (I hope!), so the class need not be mentioned.


I have not checked up, yet whether there is only one "id" or not which is
called "Sverige" but why should it be an error to specify both the class
which is the parent and the "id" which is the child?
 
L

Luigi Donatello Asero

Els said:
Luigi said:
In theory there could have been another id which is called "sverige" as

No, in theory[1] there couldn't be. In practice there could be, but it
would be wrong practice.

Do you mean that W3 recommends to use only one "id" for each page
regardless of whether it belongs to the same class or not?
If the element with the id is a child of the element with the class,
as in <div class="subsubsection"><p id="sverige">, then write it as
.subsubsection #sverige.


What does "p" stand here for?
Well,
..subsubsection#sverige was what gave an error, wasn´t it?
 
E

Els

Luigi said:
I have not checked up, yet whether there is only one "id" or not which is
called "Sverige" but why should it be an error to specify both the class
which is the parent and the "id" which is the child?

Because they are names to identify elements. One element with two
names, is not a child of itself. Is Asero a child of Donatello which
is a child of Luigi? No, they all refer to the same person.

If you write <div class="foo" id="bar">, you are giving two names to
one element. This is very much okay, and certainly has its use.
But you can't say that #bar is a child of .foo, because it's one and
the same element they refer to.
 
E

Els

Luigi said:
What does "p" stand here for?

Paragraph. It's an example, Luigi, I didn't take it from your website,
it's entirely by my personal choice that I picked a paragraph element
to pose as the child of a div with a class 'subsubsection'.
 
D

David Dorward

Els said:
Then just use #sverige. There is only one element with id 'sverige' on
the page (I hope!), so the class need not be mentioned.

The same stylesheet might be used with multiple documents with an element of
id "sverige" but different pages could have different classes assigned to
that element.
 
D

David Dorward

Luigi said:
What is wrong with this?
.subsubsection#sverige A { background-color: #99ffcc;
background-image:none;
color: #000000; display: block; text-align:center;}

I get a "class error"

From what? The W3C CSS Validator doesn't throw such an error on that code.
 
L

Luigi Donatello Asero

Els said:
Because they are names to identify elements. One element with two
names, is not a child of itself. Is Asero a child of Donatello which
is a child of Luigi? No, they all refer to the same person.

If you write <div class="foo" id="bar">, you are giving two names to
one element. This is very much okay, and certainly has its use.
But you can't say that #bar is a child of .foo, because it's one and
the same element they refer to.

Why did I get a class error then?
 
L

Luigi Donatello Asero

David Dorward said:
The same stylesheet might be used with multiple documents with an element of
id "sverige" but different pages could have different classes assigned to
that element.

It sounds reasonable.
So, actually, it is a good thing to use both the class and the id to
identify the element
"sverige" in question.
 
L

Luigi Donatello Asero

David Dorward said:
From what? The W3C CSS Validator doesn't throw such an error on that code.

The W3C CSS Validator did not seem to accept
URLs with https and for some reason did not display any results when I tried
to paste the content of the file,
so I used this one instead
http://www.htmlhelp.com/tools/csscheck/
This displayed the error as far as I remember
Afterwards I tried to make many changes in the stylesheet to improve it and
it probably needs be much improved yet
 
L

Luigi Donatello Asero

Luigi Donatello Asero said:
code.

The W3C CSS Validator did not seem to accept
URLs with https and for some reason did not display any results when I tried
to paste the content of the file,
so I used this one instead
http://www.htmlhelp.com/tools/csscheck/
This displayed the error as far as I remember
Afterwards I tried to make many changes in the stylesheet to improve it and
it probably needs be much improved yet


"Error: Classes may contain only the characters A-Z, a-z, 0-9, Unicode
161-255, hyphens, or escaped Unicode characters as numeric codes."
 
L

Luigi Donatello Asero

Luigi Donatello Asero said:
"Error: Classes may contain only the characters A-Z, a-z, 0-9, Unicode
161-255, hyphens, or escaped Unicode characters as numeric codes."



So, I guess that the validator thinks that "#" is a character of the name of
the class...
instead it means that what it follows is the name of the "id"
 
E

Els

David said:
The same stylesheet might be used with multiple documents with an element of
id "sverige" but different pages could have different classes assigned to
that element.

Yes - I actually thought of that before I wrote my reply, but I didn't
want to complicate the matter further than necessary. That is, because
I was under the impression that .foo#bar wasn't an allowed
combination.

Apparently, according to this link:
http://penguin.theopalgroup.com/cgi-bin/css3explainer/selectoracle.py
you can actually write it exactly as Luigi described.

I didn't know that though - is it correct according to the W3C spec?
 
M

Michael Winter

Luigi said:
What is wrong with this?
.subsubsection#sverige
[snip]

So, what is it, a class? (.susubsection) an id? (#sverige)?
Can't make the two into a hybrid.

Certainly can[1]. A 'simple' selector is an optional element name
(including the universal element selector, '*'), followed by any number
of attributes (including none, unless the element name is omitted), with
no intervening whitespace.

.subsubsection#sverige a

would match an anchor (A element) that is a descendant of any element
that has both a class attribute containing the word 'subsubsection' and
an id attribute value that equals 'sverige'.

This particular pattern might not be that useful - the id attribute
selector would normally suffice on its own - but it's possible that
though there may be many elements within the documents of a site with a
given id attribute value, only a subset will also have the required
class name, too.


As for what a 'class error' is, I have no idea. Unless Luigi cares to
mention where (and with what) this error apparently occurred, there's
not much I can add.

Mike


[1] See the simple_selector production in Appendix D.1 Grammar of
the CSS 2 Specification.

<http://www.w3.org/TR/REC-CSS2/grammar.html#x1>
 

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
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top