Tutorials-Good Code vs How Too

U

Uglysocks

I am trying to learn CSS. I've worked through a couple of tutorials that
explain how-to, but don't specify good programming standards. I've
recently put up a site that is based on a Strange Banana (
http://www.strangebanana.com/generator.aspx ) example. The CSS generated
by Strange Banana wants to rely on id's, but it seems to me that classes
would be better style. Are there any tutorials that emphasize good, clean
CSS for more easily maintainable sites.

Thanks
 
L

Leif K-Brooks

Uglysocks said:
The CSS generated
by Strange Banana wants to rely on id's, but it seems to me that classes
would be better style.

No they wouldn't. The only case where classes would be better than IDs
is someone using the same ID multiple times, or to specify multiple
elements of the same type (#foo1, #foo2, and #foo3 with the same style).
 
N

nj_dilettante

Leif said:
No they wouldn't. The only case where classes would be better than IDs
is someone using the same ID multiple times, or to specify multiple
elements of the same type (#foo1, #foo2, and #foo3 with the same
style).

Is the necessity for multiple use on the same page the ONLY criterion for
using CLASS rather than ID? If they function the same way, why not alway
use CLASS? I'm totally confused on this point...
 
L

Leif K-Brooks

nj_dilettante said:
Is the necessity for multiple use on the same page the ONLY criterion for
using CLASS rather than ID? If they function the same way, why not alway
use CLASS? I'm totally confused on this point...

Because ID can be used to identify elements for things besides style sheets.
 
N

nj_dilettante

Leif said:
Because ID can be used to identify elements for things besides style
sheets.

Unfortunately for me, I'm still confused. The examples I've seen in this NG
usually show the use of ID and CLASS in what seem to me to be
interchangeable situations. Can you give me an example where the ID tag
MUST be used in CSS?
 
L

Leif K-Brooks

nj_dilettante said:
Unfortunately for me, I'm still confused. The examples I've seen in this NG
usually show the use of ID and CLASS in what seem to me to be
interchangeable situations. Can you give me an example where the ID tag
MUST be used in CSS?

There are none, but it's an attribute not a tag.
 
B

brucie

Unfortunately for me, I'm still confused. The examples I've seen in this NG
usually show the use of ID and CLASS in what seem to me to be
interchangeable situations. Can you give me an example where the ID tag
MUST be used in CSS?

<quote>
The id attribute has several roles in HTML:
* As a style sheet selector.
* As a target anchor for hypertext links.
* As a means to reference a particular element from a script.
* As the name of a declared OBJECT element.
* For general purpose processing by user agents (e.g. for identifying
fields when extracting data from HTML pages into a database,
translating HTML documents into other formats, etc.).

The class attribute, on the other hand, assigns one or more class
names to an element; the element may be said to belong to these
classes. A class name may be shared by several element instances. The
class attribute has several roles in HTML:
* As a style sheet selector (when an author wishes to assign style
information to a set of elements).
* For general purpose processing by user agents.

</quote>
7.5.2 Element identifiers: the id and class attributes
http://www.w3.org/TR/html401/struct/global.html#h-7.5.2
 
K

Kris

nj_dilettante said:
Unfortunately for me, I'm still confused. The examples I've seen in this NG
usually show the use of ID and CLASS in what seem to me to be
interchangeable situations. Can you give me an example where the ID tag
MUST be used in CSS?

If you play Warcraft III:
The ID attribute is a Hero, the CLASS attribute a foot soldier.
 

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

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top