<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Don&#8217;t over-specify your CSS code</title>
	<atom:link href="http://www.robertnyman.com/2007/10/18/dont-over-specify-your-css-code/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.robertnyman.com/2007/10/18/dont-over-specify-your-css-code/</link>
	<description>Web development and Internet trends</description>
	<pubDate>Tue, 06 Jan 2009 02:36:45 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.1</generator>
		<item>
		<title>By: Goodbye 2007 - Happy New Year! - Robert&#8217;s talk</title>
		<link>http://www.robertnyman.com/2007/10/18/dont-over-specify-your-css-code/#comment-171876</link>
		<dc:creator>Goodbye 2007 - Happy New Year! - Robert&#8217;s talk</dc:creator>
		<pubDate>Sat, 29 Dec 2007 21:42:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.robertnyman.com/2007/10/18/dont-over-specify-your-css-code/#comment-171876</guid>
		<description>[...] Don’t Over-specify Your CSS Code [...]</description>
		<content:encoded><![CDATA[<p>[...] Don’t Over-specify Your <acronym title="Cascading Style Sheets">CSS</acronym> Code [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Robert Nyman</title>
		<link>http://www.robertnyman.com/2007/10/18/dont-over-specify-your-css-code/#comment-132425</link>
		<dc:creator>Robert Nyman</dc:creator>
		<pubDate>Mon, 05 Nov 2007 08:48:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.robertnyman.com/2007/10/18/dont-over-specify-your-css-code/#comment-132425</guid>
		<description>Jeremy,

Great comment! I pretty much agree whole-heartedly in everything you wrote! :-)</description>
		<content:encoded><![CDATA[<p>Jeremy,</p>
<p>Great comment! I pretty much agree whole-heartedly in everything you wrote! <img src='http://www.robertnyman.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeremy Dill</title>
		<link>http://www.robertnyman.com/2007/10/18/dont-over-specify-your-css-code/#comment-131590</link>
		<dc:creator>Jeremy Dill</dc:creator>
		<pubDate>Sat, 03 Nov 2007 16:20:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.robertnyman.com/2007/10/18/dont-over-specify-your-css-code/#comment-131590</guid>
		<description>Good article!

I've been doing quite a bit of css fixing/updating for a handful of large complex websites lately.  Some of what I am finding right along with what I am reading here.     

Here is my view on this (think of me as an outsider looking into your CSS to fix or add something).   

&lt;strong&gt;Method 1)&lt;/strong&gt; Being very specific is OK as long as you are doing it all in 1 file and you maintain a nice single line grouping (like Fabrice mentioned).

&lt;strong&gt;Method 2)&lt;/strong&gt; Using a generic method (sometimes with "Overrides" such as Roberts .side-bar .pre-amble) is a a great method for being efficient in terms of code size and reusability.  

&lt;strong&gt;Working with 1)&lt;/strong&gt; Use the CSS file like an index based on what page you are working with, find its reference and alter it.

&lt;strong&gt;Working with 2)&lt;/strong&gt; Search the CSS file for the class name (or parent) that is applying to your element.  As long as your class names/IDs aren't super short or generic (like don't name a class with less than 3 letters) it is pretty easy to find all the places where that class is referenced..and then to see what subtags are affected.  Since there is less overall CSS, it is not too difficult to figure out what is going on.  

&lt;strong&gt;Benefit of 1)&lt;/strong&gt; The benefit of method 1 is that people who are very CSS minded tend to prefer working like this...and it allows for very specific control of everything, and you don't have to crack open the html file very often.

&lt;strong&gt;Benefit of 2)&lt;/strong&gt; The benefit is that you can change things on all pages at once without having to be specific.  You can minimize your code and simplify the styling markup. (which I think was the point of this article)

&lt;strong&gt;Disadvantage of 1)&lt;/strong&gt; You have to write a lot of CSS.  You might will find yourself writing the same styling over and over again if you lock yourself into this method.   
Example - (Real example from something I had to work on):
&lt;code&gt;
#sidebar-left .links-menu li#work.active a, #sidebar-left .links-menu li#&lt;strong&gt;work&lt;/strong&gt;.active a:hover{background-position: 0px 0px;color: #fff;}
#sidebar-left .links-menu li#contact.active a, #sidebar-left .links-menu li#&lt;strong&gt;contact&lt;/strong&gt;.active a:hover{background-position: 0px 0px;color: #fff;}				
&lt;/code&gt;

&lt;strong&gt;Disadvantage of 2)&lt;/strong&gt;  Requires that you are very clever in your overall structure and design.  You have to carefully construct your HTML and your CSS to work together.  You have to pay close attention to inheritance and use it to help rather than trying to defeat it.  Doing all of this might take more time, and you might not be able to get something up and running in a hurry.

Whatever method you choose, please keep the following things in mind.  These are the things that take lots of time and headache to sort out. (at least for me)

 Please don't mix and match these 2 modes of writing CSS.  Tracing through the multiple degrees of generic to super specific tags is never a treat.
 Please keep your stuff grouped (especially critical in method 1).
 For both methods avoid multiple files.  Put it all in one file and avoid browser specific hacks or include files. It is possible  (although challenging) to write css without hacks.
For both methods, don't put in style declarations that do nothing at all.
 For method 2, don't take it to an extreme.  Don't be afraid to use classes for grouping.  Rather than putting generic styles on "li" for  example, create a class that groups all the elements inside an unordered list.  I.E. 
&lt;code&gt;
.simple_list ul{...}
.simple_list li{...}
&lt;/code&gt;

Then wrap your list 

&#60; div class="simple_list"&#62;
&#60;ul&#62;&#60;li&#62;item&#60;/li&#62;&#60;li&#62;item2&#60;/li&#62;&#60;/ul&#62;
&#60;/div&#62;

Why didn't I just use &lt;code&gt;ul.simple_list {..}&lt;/code&gt; and then apply the style to the ul tag?  Because now I have organized my css and my HTML in such a way that I can keep doing things to the .simple_list class of boxes, and it keeps things in a name space in for readability in CSS.  So, if there are hyperlinks in there for example, I just add another .simple_list a{...}.  It's not super specific, but it's not so generic that somebody might get lost.


Ok.. so you found me out.  You can probably tell that my preference is method 2. Robert, I am in your camp on this.  I think it just makes better use of the power of CSS and HTML.  Also, badly written generic code is easier to troubleshoot than badly written specific css in my opinion.

For those of you who want to make something portable, just put a single ID or unique class at the base of the styling elements to be grouped.  This will essentially create a name-space bucket  for it (#container as Robert demonstrates).  You don't have to traverse all the way down to each element.

Ya know, I thought that the point of CSS is to make things more manageable (better organized) and to create separation.  But, the way I see it, separation isn't a benefit in itself.  Separation is actually just a requirement so that we can do more things with the page content later.  

If the end result of a CSS implementation is that you need Firebug just to figure out what in the world is going on, then we might as well run with the devil an do all inline styles so we can at least find everything in one place. We haven't achieved manageability or separation in this case anyway.

happy coding to you!

- Jeremy

PS. Marco.. good point.</description>
		<content:encoded><![CDATA[<p>Good article!</p>
<p>I&#8217;ve been doing quite a bit of <acronym title="Cascading Style Sheets">CSS</acronym> fixing/updating for a handful of large complex websites lately.  Some of what I am finding right along with what I am reading here.     </p>
<p>Here is my view on this (think of me as an outsider looking into your <acronym title="Cascading Style Sheets">CSS</acronym> to fix or add something).   </p>
<p><strong>Method 1)</strong> Being very specific is OK as long as you are doing it all in 1 file and you maintain a nice single line grouping (like Fabrice mentioned).</p>
<p><strong>Method 2)</strong> Using a generic method (sometimes with &#8220;Overrides&#8221; such as Roberts .side-bar .pre-amble) is a a great method for being efficient in terms of code size and reusability.  </p>
<p><strong>Working with 1)</strong> Use the <acronym title="Cascading Style Sheets">CSS</acronym> file like an index based on what page you are working with, find its reference and alter it.</p>
<p><strong>Working with 2)</strong> Search the <acronym title="Cascading Style Sheets">CSS</acronym> file for the class name (or parent) that is applying to your element.  As long as your class names/IDs aren&#8217;t super short or generic (like don&#8217;t name a class with less than 3 letters) it is pretty easy to find all the places where that class is referenced..and then to see what subtags are affected.  Since there is less overall <acronym title="Cascading Style Sheets">CSS</acronym>, it is not too difficult to figure out what is going on.  </p>
<p><strong>Benefit of 1)</strong> The benefit of method 1 is that people who are very <acronym title="Cascading Style Sheets">CSS</acronym> minded tend to prefer working like this&#8230;and it allows for very specific control of everything, and you don&#8217;t have to crack open the <acronym title="HyperText Markup Language">HTML</acronym> file very often.</p>
<p><strong>Benefit of 2)</strong> The benefit is that you can change things on all pages at once without having to be specific.  You can minimize your code and simplify the styling markup. (which I think was the point of this article)</p>
<p><strong>Disadvantage of 1)</strong> You have to write a lot of <acronym title="Cascading Style Sheets">CSS</acronym>.  You might will find yourself writing the same styling over and over again if you lock yourself into this method.<br />
Example - (Real example from something I had to work on):<br />
<code><br />
#sidebar-left .links-menu li#work.active a, #sidebar-left .links-menu li#<strong>work</strong>.active a:hover{background-position: 0px 0px;color: #fff;}<br />
#sidebar-left .links-menu li#contact.active a, #sidebar-left .links-menu li#<strong>contact</strong>.active a:hover{background-position: 0px 0px;color: #fff;}<br />
</code></p>
<p><strong>Disadvantage of 2)</strong>  Requires that you are very clever in your overall structure and design.  You have to carefully construct your <acronym title="HyperText Markup Language">HTML</acronym> and your <acronym title="Cascading Style Sheets">CSS</acronym> to work together.  You have to pay close attention to inheritance and use it to help rather than trying to defeat it.  Doing all of this might take more time, and you might not be able to get something up and running in a hurry.</p>
<p>Whatever method you choose, please keep the following things in mind.  These are the things that take lots of time and headache to sort out. (at least for me)</p>
<p> Please don&#8217;t mix and match these 2 modes of writing <acronym title="Cascading Style Sheets">CSS</acronym>.  Tracing through the multiple degrees of generic to super specific tags is never a treat.<br />
 Please keep your stuff grouped (especially critical in method 1).<br />
 For both methods avoid multiple files.  Put it all in one file and avoid browser specific hacks or include files. It is possible  (although challenging) to write <acronym title="Cascading Style Sheets">CSS</acronym> without hacks.<br />
For both methods, don&#8217;t put in style declarations that do nothing at all.<br />
 For method 2, don&#8217;t take it to an extreme.  Don&#8217;t be afraid to use classes for grouping.  Rather than putting generic styles on &#8220;li&#8221; for  example, create a class that groups all the elements inside an unordered list.  I.E.<br />
<code><br />
.simple_list ul{...}<br />
.simple_list li{...}<br />
</code></p>
<p>Then wrap your list </p>
<p>&lt; div class=&#8221;simple_list&#8221;&gt;<br />
&lt;ul&gt;&lt;li&gt;item&lt;/li&gt;&lt;li&gt;item2&lt;/li&gt;&lt;/ul&gt;<br />
&lt;/div&gt;</p>
<p>Why didn&#8217;t I just use <code>ul.simple_list {..}</code> and then apply the style to the ul tag?  Because now I have organized my <acronym title="Cascading Style Sheets">CSS</acronym> and my <acronym title="HyperText Markup Language">HTML</acronym> in such a way that I can keep doing things to the .simple_list class of boxes, and it keeps things in a name space in for readability in <acronym title="Cascading Style Sheets">CSS</acronym>.  So, if there are hyperlinks in there for example, I just add another .simple_list a{&#8230;}.  It&#8217;s not super specific, but it&#8217;s not so generic that somebody might get lost.</p>
<p>Ok.. so you found me out.  You can probably tell that my preference is method 2. Robert, I am in your camp on this.  I think it just makes better use of the power of <acronym title="Cascading Style Sheets">CSS</acronym> and <acronym title="HyperText Markup Language">HTML</acronym>.  Also, badly written generic code is easier to troubleshoot than badly written specific <acronym title="Cascading Style Sheets">CSS</acronym> in my opinion.</p>
<p>For those of you who want to make something portable, just put a single ID or unique class at the base of the styling elements to be grouped.  This will essentially create a name-space bucket  for it (#container as Robert demonstrates).  You don&#8217;t have to traverse all the way down to each element.</p>
<p>Ya know, I thought that the point of <acronym title="Cascading Style Sheets">CSS</acronym> is to make things more manageable (better organized) and to create separation.  But, the way I see it, separation isn&#8217;t a benefit in itself.  Separation is actually just a requirement so that we can do more things with the page content later.  </p>
<p>If the end result of a <acronym title="Cascading Style Sheets">CSS</acronym> implementation is that you need Firebug just to figure out what in the world is going on, then we might as well run with the devil an do all inline styles so we can at least find everything in one place. We haven&#8217;t achieved manageability or separation in this case anyway.</p>
<p>happy coding to you!</p>
<p>- Jeremy</p>
<p>PS. Marco.. good point.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Robert Nyman</title>
		<link>http://www.robertnyman.com/2007/10/18/dont-over-specify-your-css-code/#comment-125713</link>
		<dc:creator>Robert Nyman</dc:creator>
		<pubDate>Tue, 23 Oct 2007 15:47:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.robertnyman.com/2007/10/18/dont-over-specify-your-css-code/#comment-125713</guid>
		<description>Andreas,

In theory, the more specific style rules, the slower it should be for CSS code as well. Then again, I think the difference is hardly noticeable from a performance standpoint.</description>
		<content:encoded><![CDATA[<p>Andreas,</p>
<p>In theory, the more specific style rules, the slower it should be for <acronym title="Cascading Style Sheets">CSS</acronym> code as well. Then again, I think the difference is hardly noticeable from a performance standpoint.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andreas</title>
		<link>http://www.robertnyman.com/2007/10/18/dont-over-specify-your-css-code/#comment-125654</link>
		<dc:creator>Andreas</dc:creator>
		<pubDate>Tue, 23 Oct 2007 13:56:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.robertnyman.com/2007/10/18/dont-over-specify-your-css-code/#comment-125654</guid>
		<description>I think Jeffrey Sambells said pretty much all I was thinking. I'm always too specific and I know that, but I don't mind it and to me it makes the code easier to read. Also I'm not sure you'd lose 50% of file size simply by being less specific in your selectors, the properties and their values are the majority of code in my CSS.
If I use a JS-library with support for CSS-selectors (like jQuery) I'm always as un-specific as possible because of performance issues; '#contact form p label input[name="email"]' must be slower to retrieve than just #contact input[name="email"]... or am I wrong? Also, are there performance issues with being too specific in your CSS as well?</description>
		<content:encoded><![CDATA[<p>I think Jeffrey Sambells said pretty much all I was thinking. I&#8217;m always too specific and I know that, but I don&#8217;t mind it and to me it makes the code easier to read. Also I&#8217;m not sure you&#8217;d lose 50% of file size simply by being less specific in your selectors, the properties and their values are the majority of code in my <acronym title="Cascading Style Sheets">CSS</acronym>.<br />
If I use a JS-library with support for <acronym title="Cascading Style Sheets">CSS</acronym>-selectors (like jQuery) I&#8217;m always as un-specific as possible because of performance issues; &#8216;#contact form p label input[name="email"]&#8216; must be slower to retrieve than just #contact input[name="email"]&#8230; or am I wrong? Also, are there performance issues with being too specific in your <acronym title="Cascading Style Sheets">CSS</acronym> as well?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ????? ??????? ? &#171; ???? ?? ??</title>
		<link>http://www.robertnyman.com/2007/10/18/dont-over-specify-your-css-code/#comment-125141</link>
		<dc:creator>????? ??????? ? &#171; ???? ?? ??</dc:creator>
		<pubDate>Mon, 22 Oct 2007 15:35:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.robertnyman.com/2007/10/18/dont-over-specify-your-css-code/#comment-125141</guid>
		<description>[...] • Don’t over-specify your CSS code [...]</description>
		<content:encoded><![CDATA[<p>[...] • Don’t over-specify your <acronym title="Cascading Style Sheets">CSS</acronym> code [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: &#187; CSS-Tipps: Spezifizität &#8212; cne _LOG Archiv</title>
		<link>http://www.robertnyman.com/2007/10/18/dont-over-specify-your-css-code/#comment-124931</link>
		<dc:creator>&#187; CSS-Tipps: Spezifizität &#8212; cne _LOG Archiv</dc:creator>
		<pubDate>Mon, 22 Oct 2007 09:19:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.robertnyman.com/2007/10/18/dont-over-specify-your-css-code/#comment-124931</guid>
		<description>[...] Robert Nyman befasst sich mit der Spezifizität von CSS- Anweisungen: Don’t over-specify your CSS code. [...]</description>
		<content:encoded><![CDATA[<p>[...] Robert Nyman befasst sich mit der Spezifizität von <acronym title="Cascading Style Sheets">CSS</acronym>- Anweisungen: Don’t over-specify your <acronym title="Cascading Style Sheets">CSS</acronym> code. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marco</title>
		<link>http://www.robertnyman.com/2007/10/18/dont-over-specify-your-css-code/#comment-124239</link>
		<dc:creator>Marco</dc:creator>
		<pubDate>Sat, 20 Oct 2007 23:04:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.robertnyman.com/2007/10/18/dont-over-specify-your-css-code/#comment-124239</guid>
		<description>I think lots of excessive specificity stems from the 'time is money' principle. This is especially true when developer A has to fix something in developer B's code and it has to be done in 10 minutes because people can't accept that certain things sometimes take their time.

CSS quite often tends to start out nice, compact and organised and then slowly but surely deteriorate into a mess, especially when lots of different people who all have their own way of working edit it. It takes some serious discipline, coding conventions and patience on the side of those who are in a hurry to prevent this from happening.</description>
		<content:encoded><![CDATA[<p>I think lots of excessive specificity stems from the &#8216;time is money&#8217; principle. This is especially true when developer A has to fix something in developer B&#8217;s code and it has to be done in 10 minutes because people can&#8217;t accept that certain things sometimes take their time.</p>
<p><acronym title="Cascading Style Sheets">CSS</acronym> quite often tends to start out nice, compact and organised and then slowly but surely deteriorate into a mess, especially when lots of different people who all have their own way of working edit it. It takes some serious discipline, coding conventions and patience on the side of those who are in a hurry to prevent this from happening.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SpookyET</title>
		<link>http://www.robertnyman.com/2007/10/18/dont-over-specify-your-css-code/#comment-123530</link>
		<dc:creator>SpookyET</dc:creator>
		<pubDate>Fri, 19 Oct 2007 15:10:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.robertnyman.com/2007/10/18/dont-over-specify-your-css-code/#comment-123530</guid>
		<description>http://www.thepirateship.com/sites/all/themes/thepirateship/style.css

I write boxed css code. I don't plan on switching soon. There are great advantages. I can install a forum or a gallery and reference the global CSS and style small parts of the gallery as opposed to fully styling it because there are no conflicts due to specificity.  There cases where classes are not enough, especially when you use common terms that can be used by multiple applications for different things.</description>
		<content:encoded><![CDATA[<p><a href="http://www.thepirateship.com/sites/all/themes/thepirateship/style.css" rel="nofollow">http://www.thepirateship.com/sites/all/themes/thepirateship/style.css</a></p>
<p>I write boxed <acronym title="Cascading Style Sheets">CSS</acronym> code. I don&#8217;t plan on switching soon. There are great advantages. I can install a forum or a gallery and reference the global <acronym title="Cascading Style Sheets">CSS</acronym> and style small parts of the gallery as opposed to fully styling it because there are no conflicts due to specificity.  There cases where classes are not enough, especially when you use common terms that can be used by multiple applications for different things.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Virginia DeBolt</title>
		<link>http://www.robertnyman.com/2007/10/18/dont-over-specify-your-css-code/#comment-123473</link>
		<dc:creator>Virginia DeBolt</dc:creator>
		<pubDate>Fri, 19 Oct 2007 11:56:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.robertnyman.com/2007/10/18/dont-over-specify-your-css-code/#comment-123473</guid>
		<description>I'm glad to see there are others who feel this way. Selectors get completely overblown sometimes. I especially see it in Wordpress themes.

I wonder how much of this comes about because of the way Dreamweaver pre-populates the Advanced selector field when a page element is selected in Design View and the + sign to create a new style is clicked. Dreamweaver goes through the entire page hierarchy in naming the selector, an example of far too much.</description>
		<content:encoded><![CDATA[<p>I&#8217;m glad to see there are others who feel this way. Selectors get completely overblown sometimes. I especially see it in Wordpress themes.</p>
<p>I wonder how much of this comes about because of the way Dreamweaver pre-populates the Advanced selector field when a page element is selected in Design View and the + sign to create a new style is clicked. Dreamweaver goes through the entire page hierarchy in naming the selector, an example of far too much.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Robert Nyman</title>
		<link>http://www.robertnyman.com/2007/10/18/dont-over-specify-your-css-code/#comment-123420</link>
		<dc:creator>Robert Nyman</dc:creator>
		<pubDate>Fri, 19 Oct 2007 09:01:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.robertnyman.com/2007/10/18/dont-over-specify-your-css-code/#comment-123420</guid>
		<description>Good input! And Eric Shepherd raises an interesting point, where you won't know the context and want to make sure it's not overridden by any other styles.

But I think/hope that such scenarios aren't that common, although I know they do exist. It seems they exist more in fairly large web sites and in communities.

Jeffrey Sambells ,

I think my examples are a bit too short to exemplify my point about reusage. The idea is, with .pre-amble for instance, is that many CSS properties will be the same wherever it is used. The gist is to focus on what is being general no matter where it is being used, and then code extra for exceptions. Kind of like this:

&lt;code&gt;
.pre-amble{
	color: #f00;
	font: bold 1.25em V eradna, Arial, Helvetica, sans-serif;
	text-align: center;
	margin-bottom: 1em;
	padding: 0.5em 1em 0;
	/* etc... */
}

and then just have any potential exception for the sidebar:

.side-bar .pre-amble{
	color: #000;
}
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Good input! And Eric Shepherd raises an interesting point, where you won&#8217;t know the context and want to make sure it&#8217;s not overridden by any other styles.</p>
<p>But I think/hope that such scenarios aren&#8217;t that common, although I know they do exist. It seems they exist more in fairly large web sites and in communities.</p>
<p>Jeffrey Sambells ,</p>
<p>I think my examples are a bit too short to exemplify my point about reusage. The idea is, with .pre-amble for instance, is that many <acronym title="Cascading Style Sheets">CSS</acronym> properties will be the same wherever it is used. The gist is to focus on what is being general no matter where it is being used, and then code extra for exceptions. Kind of like this:</p>
<p><code><br />
.pre-amble{<br />
	color: #f00;<br />
	font: bold 1.25em V eradna, Arial, Helvetica, sans-serif;<br />
	text-align: center;<br />
	margin-bottom: 1em;<br />
	padding: 0.5em 1em 0;<br />
	/* etc... */<br />
}</p>
<p>and then just have any potential exception for the sidebar:</p>
<p>.side-bar .pre-amble{<br />
	color: #000;<br />
}<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anton Andreasson</title>
		<link>http://www.robertnyman.com/2007/10/18/dont-over-specify-your-css-code/#comment-123341</link>
		<dc:creator>Anton Andreasson</dc:creator>
		<pubDate>Fri, 19 Oct 2007 06:20:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.robertnyman.com/2007/10/18/dont-over-specify-your-css-code/#comment-123341</guid>
		<description>I usually split up my rules so that all generic things about a "help box" (for instance) is declared within, say the .help rule. Then I use wrapper ID:s, layout classes or what I find is most suitable to specify the layout/placement specific aspects of the help-box, when placed in different contexts. 

About having element names before classes: I find this very useful when I have general class names (like .help) where I might use a.help or img.help elsewhere in the markup. Using div.help leaves the clashes out of question that way.</description>
		<content:encoded><![CDATA[<p>I usually split up my rules so that all generic things about a &#8220;help box&#8221; (for instance) is declared within, say the .help rule. Then I use wrapper ID:s, layout classes or what I find is most suitable to specify the layout/placement specific aspects of the help-box, when placed in different contexts. </p>
<p>About having element names before classes: I find this very useful when I have general class names (like .help) where I might use a.help or img.help elsewhere in the markup. Using div.help leaves the clashes out of question that way.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jermayn Parker</title>
		<link>http://www.robertnyman.com/2007/10/18/dont-over-specify-your-css-code/#comment-123244</link>
		<dc:creator>Jermayn Parker</dc:creator>
		<pubDate>Fri, 19 Oct 2007 01:22:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.robertnyman.com/2007/10/18/dont-over-specify-your-css-code/#comment-123244</guid>
		<description>Another benefit is that seeing you are less anal about lCSS development meaning you will generally enjoy life more :D</description>
		<content:encoded><![CDATA[<p>Another benefit is that seeing you are less anal about lCSS development meaning you will generally enjoy life more <img src='http://www.robertnyman.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steven Clark</title>
		<link>http://www.robertnyman.com/2007/10/18/dont-over-specify-your-css-code/#comment-123162</link>
		<dc:creator>Steven Clark</dc:creator>
		<pubDate>Thu, 18 Oct 2007 20:22:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.robertnyman.com/2007/10/18/dont-over-specify-your-css-code/#comment-123162</guid>
		<description>Good advice Robert, especially to anyone just learning CSS so they have the mental tools to assess when it is true and when they may need to overly specify as in cases mentioned in the comments so far (working with others).

I think the rule often quoted is start general and get more specific as you find the exceptional cases.</description>
		<content:encoded><![CDATA[<p>Good advice Robert, especially to anyone just learning <acronym title="Cascading Style Sheets">CSS</acronym> so they have the mental tools to assess when it is true and when they may need to overly specify as in cases mentioned in the comments so far (working with others).</p>
<p>I think the rule often quoted is start general and get more specific as you find the exceptional cases.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tanny O'Haley</title>
		<link>http://www.robertnyman.com/2007/10/18/dont-over-specify-your-css-code/#comment-123140</link>
		<dc:creator>Tanny O'Haley</dc:creator>
		<pubDate>Thu, 18 Oct 2007 19:20:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.robertnyman.com/2007/10/18/dont-over-specify-your-css-code/#comment-123140</guid>
		<description>Over the past two years I've become more minimalistic with my CSS. However, I'm with Eric Shepherd on being very specific when I write a module that will be used by other developers. About 40% of what I do at my job is write utilities for use by other developers where I work.

In the past, I've been burned because my CSS was not specific enough and the developer CSS overwrote my styles. This happened with my dropdown calendar. A developer's styles made the calendar text so small that it was unreadable. Instead of the "Today" link being centered it was right justified. Then they complained that the problem was with my utility, and they were right, I needed to be more specific.

So while I agree with you for general page styles, when writing a utility that is going to be used by other developers, I have to protect my clients by being very specific with the CSS styles for that utility. If the developer needs to overwrite a style, they can do it by being just as specific. That requires them to intentionally want to make a change to the style of the utility.</description>
		<content:encoded><![CDATA[<p>Over the past two years I&#8217;ve become more minimalistic with my <acronym title="Cascading Style Sheets">CSS</acronym>. However, I&#8217;m with Eric Shepherd on being very specific when I write a module that will be used by other developers. About 40% of what I do at my job is write utilities for use by other developers where I work.</p>
<p>In the past, I&#8217;ve been burned because my <acronym title="Cascading Style Sheets">CSS</acronym> was not specific enough and the developer <acronym title="Cascading Style Sheets">CSS</acronym> overwrote my styles. This happened with my dropdown calendar. A developer&#8217;s styles made the calendar text so small that it was unreadable. Instead of the &#8220;Today&#8221; link being centered it was right justified. Then they complained that the problem was with my utility, and they were right, I needed to be more specific.</p>
<p>So while I agree with you for general page styles, when writing a utility that is going to be used by other developers, I have to protect my clients by being very specific with the <acronym title="Cascading Style Sheets">CSS</acronym> styles for that utility. If the developer needs to overwrite a style, they can do it by being just as specific. That requires them to intentionally want to make a change to the style of the utility.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark Ferree</title>
		<link>http://www.robertnyman.com/2007/10/18/dont-over-specify-your-css-code/#comment-123107</link>
		<dc:creator>Mark Ferree</dc:creator>
		<pubDate>Thu, 18 Oct 2007 17:57:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.robertnyman.com/2007/10/18/dont-over-specify-your-css-code/#comment-123107</guid>
		<description>I think that !important has an unnecessary bad reputation.

I have noticed many people using code like:

&lt;code&gt;
html body #wrapper #nav {...}
&lt;/code&gt;

Just to avoid using !important.  

When I'm scanning through a css file !important will jump out at me as a "hack" but the above code will not stand out as easily.  Seeing !important lets me know immediately what I'm dealing with.

In a perfect world we would avoid both, but as we all know the web is not a perfect world.</description>
		<content:encoded><![CDATA[<p>I think that !important has an unnecessary bad reputation.</p>
<p>I have noticed many people using code like:</p>
<p><code><br />
<acronym title="HyperText Markup Language">HTML</acronym> body #wrapper #nav {...}<br />
</code></p>
<p>Just to avoid using !important.  </p>
<p>When I&#8217;m scanning through a <acronym title="Cascading Style Sheets">CSS</acronym> file !important will jump out at me as a &#8220;hack&#8221; but the above code will not stand out as easily.  Seeing !important lets me know immediately what I&#8217;m dealing with.</p>
<p>In a perfect world we would avoid both, but as we all know the web is not a perfect world.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeffrey Sambells</title>
		<link>http://www.robertnyman.com/2007/10/18/dont-over-specify-your-css-code/#comment-123102</link>
		<dc:creator>Jeffrey Sambells</dc:creator>
		<pubDate>Thu, 18 Oct 2007 17:40:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.robertnyman.com/2007/10/18/dont-over-specify-your-css-code/#comment-123102</guid>
		<description>I partially agree but let's not forget about semantics of classifying and identifying elements. 

I agree that something like:
&lt;code&gt;
div#container div#header ul#navigation li{
    float: left;
}
&lt;/code&gt;
is redundant simply because ID's such as #navigation only appear once in a document (according to spec) so having multiple ID's in the rule isn't really useful since there's only one #navigation anyways. The only exception is if you're using a dynamic CMS that keeps moving #navigation around in the markup (but if that's happening then you've probably got other issues).

However, the example of 
&lt;code&gt;
.pre-amble{
	margin-top: 1em;
}
&lt;/code&gt;
can often cause problems if it's too vague. If 'pre-amble' is a class then I would assume there are multiple pre-amble classes scattered about the page, on different elements. Now you've said they should all have a specific margin but in reality the pre-amble in the sidebar will probably be different than the one in the main content area. In this situation, if there's only one pre-amble, it  might be better as an ID (the pre-amble of the content area) or, like you said, something like:
&lt;code&gt;
#content .pre-amble{
    margin-top: 1em;
}
&lt;/code&gt;
I've found a lot of the issue can be resolved by defining common classes that should always be associated with an element. For example, .first could be used to indicate the first in a set of elements (if you ignore advanced selectors). Then you can do:
&lt;code&gt;
#navigation li.first { }
#content p.first {}
etc...
&lt;/code&gt; 
but you'd never use .first all by itself.

The problem mostly arises when you're working in a team so I guess the trick is to make sure everyone in your team is on the same page regardless of which methods you choose to use. Advantages of smaller file size, reusability and readability are great but reusability can also be a disadvantage if that's not what was intended by the rest of the team. If it's too reusable then you'll be back to !important again.</description>
		<content:encoded><![CDATA[<p>I partially agree but let&#8217;s not forget about semantics of classifying and identifying elements. </p>
<p>I agree that something like:<br />
<code><br />
div#container div#header ul#navigation li{<br />
    float: left;<br />
}<br />
</code><br />
is redundant simply because ID&#8217;s such as #navigation only appear once in a document (according to spec) so having multiple ID&#8217;s in the rule isn&#8217;t really useful since there&#8217;s only one #navigation anyways. The only exception is if you&#8217;re using a dynamic <acronym title="Content Management System">CMS</acronym> that keeps moving #navigation around in the markup (but if that&#8217;s happening then you&#8217;ve probably got other issues).</p>
<p>However, the example of<br />
<code><br />
.pre-amble{<br />
	margin-top: 1em;<br />
}<br />
</code><br />
can often cause problems if it&#8217;s too vague. If &#8216;pre-amble&#8217; is a class then I would assume there are multiple pre-amble classes scattered about the page, on different elements. Now you&#8217;ve said they should all have a specific margin but in reality the pre-amble in the sidebar will probably be different than the one in the main content area. In this situation, if there&#8217;s only one pre-amble, it  might be better as an ID (the pre-amble of the content area) or, like you said, something like:<br />
<code><br />
#content .pre-amble{<br />
    margin-top: 1em;<br />
}<br />
</code><br />
I&#8217;ve found a lot of the issue can be resolved by defining common classes that should always be associated with an element. For example, .first could be used to indicate the first in a set of elements (if you ignore advanced selectors). Then you can do:<br />
<code><br />
#navigation li.first { }<br />
#content p.first {}<br />
etc...<br />
</code><br />
but you&#8217;d never use .first all by itself.</p>
<p>The problem mostly arises when you&#8217;re working in a team so I guess the trick is to make sure everyone in your team is on the same page regardless of which methods you choose to use. Advantages of smaller file size, reusability and readability are great but reusability can also be a disadvantage if that&#8217;s not what was intended by the rest of the team. If it&#8217;s too reusable then you&#8217;ll be back to !important again.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nik</title>
		<link>http://www.robertnyman.com/2007/10/18/dont-over-specify-your-css-code/#comment-123070</link>
		<dc:creator>Nik</dc:creator>
		<pubDate>Thu, 18 Oct 2007 16:15:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.robertnyman.com/2007/10/18/dont-over-specify-your-css-code/#comment-123070</guid>
		<description>Robert,

I can see your point, but I use specification as a way of organizing my CSS. If I will only use a class called .warning in one section, I will still put at least the containing div id before it to remind myself where this style is being used, e.g.

&lt;code&gt;#mainBox p.warning { ... }&lt;/code&gt;

instead of 

&lt;code&gt; p.warning { ... } &lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Robert,</p>
<p>I can see your point, but I use specification as a way of organizing my <acronym title="Cascading Style Sheets">CSS</acronym>. If I will only use a class called .warning in one section, I will still put at least the containing div id before it to remind myself where this style is being used, e.g.</p>
<p><code>#mainBox p.warning { ... }</code></p>
<p>instead of </p>
<p><code> p.warning { ... } </code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anders M.J.</title>
		<link>http://www.robertnyman.com/2007/10/18/dont-over-specify-your-css-code/#comment-123060</link>
		<dc:creator>Anders M.J.</dc:creator>
		<pubDate>Thu, 18 Oct 2007 15:39:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.robertnyman.com/2007/10/18/dont-over-specify-your-css-code/#comment-123060</guid>
		<description>The CSS on my blog is currently over-specified, but I plan to change it when I get around to it. The reason it is, is because I started out by deleting the &lt;em&gt;style.css&lt;/em&gt; file in the default theme and then wrote it from the ground and up. Problem was, that one browser (can't remember which one) had trouble if I left out the element name (&lt;em&gt;div&lt;/em&gt;) before the ID name, e.g. this worked:
&lt;code&gt;
div#page {
/* styles here */
}
&lt;/code&gt;
This didn't:
&lt;code&gt;
#page {
/* styles here */
}
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>The <acronym title="Cascading Style Sheets">CSS</acronym> on my blog is currently over-specified, but I plan to change it when I get around to it. The reason it is, is because I started out by deleting the <em>style.css</em> file in the default theme and then wrote it from the ground and up. Problem was, that one browser (can&#8217;t remember which one) had trouble if I left out the element name (<em>div</em>) before the ID name, e.g. this worked:<br />
<code><br />
div#page {<br />
/* styles here */<br />
}<br />
</code><br />
This didn&#8217;t:<br />
<code><br />
#page {<br />
/* styles here */<br />
}<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Deborah</title>
		<link>http://www.robertnyman.com/2007/10/18/dont-over-specify-your-css-code/#comment-123041</link>
		<dc:creator>Deborah</dc:creator>
		<pubDate>Thu, 18 Oct 2007 14:59:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.robertnyman.com/2007/10/18/dont-over-specify-your-css-code/#comment-123041</guid>
		<description>Thanks for the reminder on CSS specificity. Sometimes it's just hard to remember when you're struggling with a display issue in browsers.</description>
		<content:encoded><![CDATA[<p>Thanks for the reminder on <acronym title="Cascading Style Sheets">CSS</acronym> specificity. Sometimes it&#8217;s just hard to remember when you&#8217;re struggling with a display issue in browsers.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
