|
Posted by Neredbojias on 07/06/06 07:28
To further the education of mankind, "Andy Dingley
<dingbat@codesmiths.com>" <dingbat@codesmiths.com> vouchsafed:
> Neredbojias wrote:
>
>> >> #domaener { font-size:5500px; }
>> >> ul .subsubsection { color:chartreuse;background:vermillion; }
>> >>
>> >> in the stylesheet.
>> >
>> > Why?
>>
>> The class is then not "linked" to the id and can be used as a true
class
>> elsewhere. Why impose unnecessary limits?
>
> Good intent, but I don't think this CSS change gives any practical
> benefit.
>
> The "class" is the classname 'subsubsection' Nothing more than this.
> There's no concept of either "ul .subsubsection" or "color and
> background" existing anywhere here. It's not demonstrably wrong to
> invent one, but it's certainly superfluous.
>
> If we did invent a subsubsection class, then we might wish to apply
> colours to it, and colours other than chartreuse (maybe a nice shade
> of fuchsia?). We might even want to go around applying this particular
> colour combination to lots of <ul> elements. In that case, then the CSS
> rules you've specified here would become downright confusing.
>
> It's unusual to apply both class and id to an element solely for the
> purpose of selecting CSS. However it's perfectly valid HTML to do so,
> and it's almost commonplace to do so (imagine a class used to indicate
> CSS selection and an id used for DHTML). There are even fairly common
> CSS techniques where combinations are useful, notably a menu with id
> values that are constant from page to page and a class of "current"
> that moves between elements.
>
> We can even say that in general it's better HTML design to code around
> attaching CSS to a class attribute and DHTML to an ID attribute. This
> is because id "binds more tightly" than class in CSS, sufficiently
> tight that it's awkward to work with (it's hard to make more specific
> selectors than an existing id selector)
>
> However in the case we have here, the problem was to apply CSS to an
> element
> <ul class="subsubsection" id="domaener">
>
> We can do this by the combination. We can do this by class, or we can
> do this by id. Without knowing the fuller context of the problem, it's
> just un-knowable to know which is best. However we can (from
> soundly-based best-practice arguments) saying that arbitrarily slicing
> the CSS in two and attaching each half to different selectors certainly
> _isn't_ a supportable decision.
I quite agree with your explanation. Generally, I use ids unless there
is a reason not to, but in this case it's hard to say what is _optimal_
without knowing the scope of the page(s). (Class is, of course,
preferable for assigning multi-element attributes.)
--
Neredbojias
Infinity has its limits.
Navigation:
[Reply to this message]
|