|
Mailing Lists
|
Home /
Groups /
Cascading Style Sheets (CSS)
Class prefixing
Is it better to have classes as p.classname or .classname? Assuming that the classname will only be used with paragraphs. If tag prefixing is better, then does it apply to ids as well? #div.header instead of #header?Michael Dinowitz 04/18/07 01:14 P Depends on what you want to do.Sandra Clark 04/18/07 01:25 P Assuming a class will only be used for a single tag, is there any performance or other reason to prefix it?Michael Dinowitz 04/19/07 03:26 P It shouldn't cause a performance problem.Sandra Clark 04/19/07 04:31 P For tags/ids... I agree entirely with Sasha.Peter Boughton 04/18/07 06:26 P Is it better to have classes as p.classname or .classname? Assuming that the classname will only be used with paragraphs. If tag prefixing is better, then does it apply to ids as well? #div.header instead of #header? Thanks Depends on what you want to do. A class that can be applied to all types of elements should be .classname. That way it can be applied to any element that has the classname. p.classname will only be applied to paragraphs An id is unique to a page. So div#id and #id are semantically equivalent. I tend to use the element name prior to the id for better documentation. Sandra Clark ============= http://www.shayna.com Training and Consulting in CSS and Accessibility Team Fusebox Is it better to have classes as p.classname or .classname? Assuming that the classname will only be used with paragraphs. If tag prefixing is better, then does it apply to ids as well? #div.header instead of #header? Thanks Assuming a class will only be used for a single tag, is there any performance or other reason to prefix it? Also, will the tag prefixing of IDs fail on any browser or cause any problems? Will it have any performance effect? I like the idea of div#header for documentation sake. I know performance is not really a factor but when I see my browsers taking huge amounts of memory, I want to be sure that one of my sites is not contributing to that memory 'loss'. Less processing and/or less work by the browser is what I mean by performance, not really speed. Thanks ----- Excess quoted text cut - see Original Post for more ----- It shouldn't cause a performance problem. If you use .class rather than element.class for an item that only is supposed to be used on a single element, then you run the risk of someone, somewhere reusing that class on something else and having it mess up down the line. My rule of thumb is that if it is only supposed to work with one element, then write it as such. Remember your CSS is cached, so its not a performance issue at all. Pages done in this way actually give a better user experience in terms of speed since pages render faster anyways. Sandra Clark ============= http://www.shayna.com Training and Consulting in CSS and Accessibility Team Fusebox Assuming a class will only be used for a single tag, is there any performance or other reason to prefix it? Also, will the tag prefixing of IDs fail on any browser or cause any problems? Will it have any performance effect? I like the idea of div#header for documentation sake. I know performance is not really a factor but when I see my browsers taking huge amounts of memory, I want to be sure that one of my sites is not contributing to that memory 'loss'. Less processing and/or less work by the browser is what I mean by performance, not really speed. Thanks ----- Excess quoted text cut - see Original Post for more ----- For tags/ids... I agree entirely with Sasha. (it's not necessary but it can help with readability, especially when the id is not on a div) For tags/classes, I think we agree, but just wanted to post an example that I think clarifies things. Rather than "what you want to do", I think I'd say it depends on the context of the class. Example: <a class="external"...>...</a> - that's something that should be "a.external", because 'external' only really has meaning to a link. Compared to: <a class="new"...>...</a> - that should just be ".new" - because it's a class that could logically apply to non-links also, even if it never does, it still potentially has meaning outside of links. Does that make sense? ----- Excess quoted text cut - see Original Post for more -----
|
May 20, 2013
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||