On Wed, September 14, 2005 6:35 am, Laurie Harper said:
> I never said you *shouldn't* use 'class' to style elements :-)
True enough :)
> That's the right answer when you want to apply the same set of styles to
> multiple elements (although even without the 'class' attribute here,
> you'd still only need to define one rule in the stylesheet... it would
> just jave 3 selectors).
Yeah, that's true. Even still though, 3 selectors feels like a little
more complexity than there needs to be. I suppose it's like preferring
a++; over a=a+1; ... neither is complicated by any stretch, but the
postfix just seems slightly cleaner. I know some people feel the exact
opposite though, so I'm coming down to personal preference, not the basis
of a strong argument :)
>> Specifically, the first sentence of the last paragraph:
>>
>> "The use of ID is appropriate when a style only needs to be applied once
>> in any document."
>>
>> That's another way of saying what I was trying to say above :)
>
> Note that there's no corollary there that this is in any way
> inappropriate, though. If I only *want* to apply styles to one element
> in the document, this is the way to do it.
Yes, I definitely agree there is nothing saying that is inappropriate. I
would still make the argument however that it semantically doesn't feel
right... it's almost as if instead of saying:
class B extends A { }
...I instead did something like:
B b(extendsA) = new B();
That's of course not real syntax, but pretend it is :) What I'm trying to
say is that it's almost like I'm tying what class B extends into the
identification of an instance of B. That's what using the ID feels like
to me.
> There's a difference between class and style, though. Class and ID are
> two different 'hooks' by which you can associate style with (one or
> more) elements. CSS provides all sorts of selectors besides class
> selectors, after all.
True enough :)
> 'id' is guaranteed unique in any valid document, whereas 'class' is
> (obviously) not. So, if I know that the thing I want to style should
> occur exactly once (for example, a title at the start of an article) I
> can assign it an ID. By attaching styles via the ID, I can be sure those
> styles will never be applied anywhere else in the document, because the
> ID must be unique. If it's not, I'll get an error when I validate the
> document.
>
> On the other hand, if I use 'class' instead of 'id', that class could be
> re-used elsewhere in the document. That won't be caught by validation,
> or anything else but visual inspection of the result.
Ah, gotcha.
> OK, so it probably not something you care about very often ;-) My point
> was just that, while IDs must be unique and that uniqueness is checked
> during validation, no such restriction applies to 'class'.
Makes sense. Yeah, I'm not sure how often it would come up, but if
someone knew it would be a concern, and I could see where it might be if
you have a lot of page designers working in parallel, you might be able to
convince me on this basis.
> Heh :) Have you had any experiences where using CSS ID selectors was
> actually bad, or caused problems?
No, I can't say that I have.
Ok, I will amend my original comment after this discussion...
It's considered a bad practice, but only by me :) And not for any real,
concrete technical reasons, just because it doesn't quite *feel* right :)
> L.
(F)rank :)
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]