Sent by M Wilson on 29 September 2004 20:08
Hi,
In any HTML markup, id selectors should be unique to a page--I believe
this is part of the CSS and XHTML spec, but I'm not sure. Does ASP.Net
require id's to be unique beyond the page level and does ASP.Net somehow
interfere with CSS using the ids provided in the markup?
Regardless, class and id selectors are very similar, but I think using
id's does offer a few advantages. Id selectors seem to be more elegant
and human readable than classes (but that also depends greatly on the
author) and id's identify unique elements within the page such as
navigation and headings. Another advantage of using id selectors is
Specificity. An id applied to an element will have a greater specificity
than a class applied to the same element using a class, to the element
itself, or both combined. Compound id's (#container #nav a) provide even
greater specificity and allows for a more granular control of page
sections than classes alone. In addition, id's can be used within
scripts and as anchor targets where class cannot. Classes do, however,
have one distinct advantage over id's: applying a style to multiple
elements on the same page, but even then, only in certain situations.
You can easily apply a style to all img elements within a div element
using #myDiv img {rules} just as you can with .myDiv img {rules}.
Essentially, you can use classes in such a fashion as to make them
nearly identical to the usage of id's, but then it's just as simple to
use id's to begin with and take advantage of the other benefits and only
use classes when necessary. In truth, I don't think one method can be
considered _worse_ than the other.
Best regards,
Mike Wilson
Jeff Ward wrote:
>I actually have a question about this. As an ASP.NET programmer, I find
>using the content selectors neigh impossible (id is used in ASP.NET to
>identify controls, and each one must be unique). I therefore have been
>using classes of objects for both ASP compatibility and because, for me,
>using id suggests a one and only one relationship, whereas the entire reason
>for me to use CSS was to generalize the look and feel of the page.
>
______________________________________________________________________
css-discuss [EMAIL-REMOVED]]
http://www.css-discuss.org/mailman/listinfo/css-d
List wiki/FAQ -- http://css-discuss.incutio.com/
Supported by evolt.org -- http://www.evolt.org/help_support_evolt/