/for/  the strong vs,  /are/ strong

 .... yup there sure is a difference... the strong programmer knows
when to use a hammer (ids) instead of an artist's paintbrush (classes)

On 1/21/07, Karl Swedberg <[EMAIL PROTECTED]> wrote:
>
> Well put, Klaus.
>
> Another difference between classes and IDs lies in the way CSS treats them.
> Whether or not you believe that classes are /for/ the strong, they
> themselves are "weaker" than IDs, at least as far as CSS is concerned.
>
> Consider this HTML snippet:
>
> <body>
>  <div class="weak">
>  <div class="enervated">
>  <p id="mighty" class="feeble">
>  What color is my text?
>  </p>
>  </div>
>  </div>
>  </body>
>
> And this CSS:
>
> #mighty {
>   color: red;
> }
> body div.weak div.enervated p.feeble {
>   color: blue;
> }
>
> Which color do you think the text will be? It certainly looks like the rule
> with all the elements and classes strung together should win out. After all,
> it's more "specific," right? And it comes after the ID rule in the
> stylesheet.
>
> Actually, though, the text will be red. Given an equal cascade (DOM) depth,
> an ID will always trump any number of elements, classes, and pseudo-classes.
> (see this in action at
> http://test.learningjquery.com/boundlink.htm)
>
> I know this will seem elementary to the CSS gurus out there, but I thought
> it might bear repeating in light of the discussion. :)
>
> --Karl
> _________________
> Karl Swedberg
> www.englishrules.com
> www.learningjquery.com
>
>
>
>
>
> On Jan 21, 2007, at 6:26 AM, Klaus Hartl wrote:
>
> Gerry Danen wrote:
> Hello Jake,
>
> I'm an IT veteran (36 years) but rather new to JavaScript, AJAX and all
> that. You voice rather strong opinions on this particular subject, and I
> love to learn. Is there any chance of a tutorial or example page on this?
>
> Or, maybe there is an example already?
>
> There is a reason that there is an id as well as a class attribute.
> These attributes are semantically different. That means one should use
> them where appropriate and not because one is feeling "stronger" by
> using classes. The id attribute also has some more functionality then
> simply being a selector hook.
>
> http://www.w3.org/TR/REC-html40/struct/global.html#h-7.5.2
>
> Maybe sometimes you will want to use an id simply because it will make
> your script much faster - at least with jQuery 1.0 ;-)
>
> I don't like such generalised statements like the one in the subject of
> this thread. They're misleading, especially for newcomers (and I
> wouldn't expect these from teachers). Classitis anyone?
>
> Apart from that it isn't correct in a sense either. If you're keen on
> avoiding unnecessary attributes for selecting things by a selector, you
> should be able to do it without classes via the pure document structure.
>
> But because IE6 doesn't support advanced CSS2 selectors, for styling you
> will have to use ids and classes in your document anyway, if you want to
> support that browser that is. So choose the names for them wisely (avoid
> presentational naming) and use context whenever possible (avoid classitis).
>
> I think the Prototype library has pushed some bad practice for extensive
> id usage because until they got the $$ selector function ids were used
> for everything. Ok, actually it's not the fault of prototype - if jQuery
> wouldn't have had the selectors it would have been the same with jQuery.
> It's just that Prototype is being used by a lot more people. I have seen
> this with developers switching from Prototype to jQuery. They tend to
> use ids instead of using the capacities of the selector engine.
>
>
> -- Klaus
>
>
> _______________________________________________
> jQuery mailing list
> [email protected]
> http://jquery.com/discuss/
>
> _______________________________________________
> jQuery mailing list
> [email protected]
> http://jquery.com/discuss/
>
>
>


-- 
Ⓙⓐⓚⓔ - יעקב   ʝǡǩȩ   ᎫᎪᏦᎬ
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to