<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:admin="http://webns.net/mvcb/"
     xmlns:content="http://purl.org/rss/1.0/modules/content/"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
	<channel> 

	<title>Comments on: CSS organisation tips</title>
	<link>http://ask.metafilter.com/21312/CSS-organisation-tips/</link>
	<description>Comments on Ask MetaFilter post CSS organisation tips</description>
	<pubDate>Sun, 17 Jul 2005 06:24:29 -0800</pubDate>
	<lastBuildDate>Sun, 17 Jul 2005 06:24:29 -0800</lastBuildDate>
	<language>en-us</language>
	<docs>http://blogs.law.harvard.edu/tech/rss</docs>
	<ttl>60</ttl>

	<item>
		<title>Question: CSS organisation tips</title>
		<link>http://ask.metafilter.com/21312/CSS-organisation-tips</link>	
		<description>Looking for useful ways to organise CSS rules.  There are many different ways of structuring CSS, which ones work for you? &lt;br /&gt;&lt;br /&gt; Douglas Bowman demonstrates a handy technique for  &lt;a href=&quot;http://www.stopdesign.com/log/2005/05/03/css-tip-flags.html&quot;&gt; flagging key sections&lt;/a&gt; in his stylesheets. Any similar tips? How do you comment and organise your styles?</description>
		<guid isPermaLink="false">post:ask.metafilter.com,2005:site.21312</guid>
		<pubDate>Sun, 17 Jul 2005 03:01:22 -0800</pubDate>
		<dc:creator>amestoy</dc:creator>
		
			<category>css</category>
		
			<category>design</category>
		
	</item> <item>
		<title>By: malevolent</title>
		<link>http://ask.metafilter.com/21312/CSS-organisation-tips#344636</link>	
		<description>I put styles applying to tags (e.g. body { } ) at the start, followed by general-purpose classes (e.g. .error { } ). Then I group by area of the page, using descendent selectors, e.g.&lt;br&gt;
&lt;br&gt;
#content p { ... }&lt;br&gt;
#content h1 { ... }&lt;br&gt;
&lt;br&gt;
#navigation ul { ... }&lt;br&gt;
#navigation li { ... }&lt;br&gt;
#navigation li.selected { ... }&lt;br&gt;
&lt;br&gt;
By doing that I find I rarely need to add comments or worry about clashing rules.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2005:site.21312-344636</guid>
		<pubDate>Sun, 17 Jul 2005 06:24:29 -0800</pubDate>
		<dc:creator>malevolent</dc:creator>
	</item><item>
		<title>By: normy</title>
		<link>http://ask.metafilter.com/21312/CSS-organisation-tips#344647</link>	
		<description>CSS ignores white space. Indenting rules to reflect the page&apos;s hierarchy of tags can make quickly scanning through a style sheet to locate particular rules easier.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2005:site.21312-344647</guid>
		<pubDate>Sun, 17 Jul 2005 07:13:41 -0800</pubDate>
		<dc:creator>normy</dc:creator>
	</item><item>
		<title>By: robhuddles</title>
		<link>http://ask.metafilter.com/21312/CSS-organisation-tips#344676</link>	
		<description>I&apos;ll second Malevolent&apos;s method, which is exactly what I do as well. It seems to me that adding a lot of comments and lines of dashes and whatnot, as in the link, also adds a lot of extar bytes to the file. If that works for you, fine, but just having a logical approach should make all those extra bytes unneccessary.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2005:site.21312-344676</guid>
		<pubDate>Sun, 17 Jul 2005 08:47:55 -0800</pubDate>
		<dc:creator>robhuddles</dc:creator>
	</item><item>
		<title>By: freudianslipper</title>
		<link>http://ask.metafilter.com/21312/CSS-organisation-tips#344710</link>	
		<description>Well I add comments only on occassion and it&apos;s usually when I hand the files over to a client.&lt;br&gt;
&lt;br&gt;
ie: /*Navigation*/&lt;br&gt;
&lt;br&gt;
But recently I have been using Bowman&apos;s flagging approach and I find it very helpful while editing and writing the CSS.&lt;br&gt;
&lt;br&gt;
But for the most part I structure all my CSS in a similar order that makes it easier for me when I&apos;m looking for something. Body, Link, Wrap, Header, Content, Leftbar, Rightbar, Footer, Cleaner. &lt;br&gt;
&lt;br&gt;
So in summation define an order structure and flags. Also extremely helpful is using &lt;a href=&quot;http://www.456bereastreet.com/archive/200502/efficient_css_with_shorthand_properties/&quot;&gt;CSS shorthand techniques&lt;/a&gt;.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2005:site.21312-344710</guid>
		<pubDate>Sun, 17 Jul 2005 09:51:05 -0800</pubDate>
		<dc:creator>freudianslipper</dc:creator>
	</item><item>
		<title>By: signal</title>
		<link>http://ask.metafilter.com/21312/CSS-organisation-tips#344722</link>	
		<description>Keep in mind that in some (very-) specific cases the order of rules matters. e.g.: when assigning 2 classes to the same element, the first class definition takes precedence.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2005:site.21312-344722</guid>
		<pubDate>Sun, 17 Jul 2005 10:15:46 -0800</pubDate>
		<dc:creator>signal</dc:creator>
	</item><item>
		<title>By: freudianslipper</title>
		<link>http://ask.metafilter.com/21312/CSS-organisation-tips#344737</link>	
		<description>good note signal, definitely worth mentioning.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2005:site.21312-344737</guid>
		<pubDate>Sun, 17 Jul 2005 10:55:49 -0800</pubDate>
		<dc:creator>freudianslipper</dc:creator>
	</item><item>
		<title>By: kirkaracha</title>
		<link>http://ask.metafilter.com/21312/CSS-organisation-tips#344780</link>	
		<description>Setting the paddings and margins to zero for everything and then only adding margins or padding as needed goes a long way toward minimizing cross-browser display inconsistencies.&lt;br&gt;
&lt;br&gt;
I usually add these styles to the top of my style sheets:&lt;br&gt;
&lt;code&gt;&lt;br&gt;
* {&lt;br&gt;
	margin: 0;&lt;br&gt;
	padding: 0;&lt;br&gt;
	border: 0;&lt;br&gt;
	}&lt;br&gt;
&lt;br&gt;
address {&lt;br&gt;
	font-style:normal;&lt;br&gt;
	}&lt;br&gt;
&lt;br&gt;
th,th {&lt;br&gt;
	vertical-align: top;&lt;br&gt;
	}&lt;br&gt;
&lt;br&gt;
option {&lt;br&gt;
	min-width: 1.5em;&lt;br&gt;
	}&lt;br&gt;
&lt;br&gt;
p,dd,ol,ul {&lt;br&gt;
	margin-bottom: 1em;&lt;br&gt;
	}&lt;br&gt;
&lt;br&gt;
table {&lt;br&gt;
	margin-top: 1em;&lt;br&gt;
	margin-bottom: 1em;&lt;br&gt;
	}&lt;br&gt;
&lt;br&gt;
ol {&lt;br&gt;
	margin-left: 27px;&lt;br&gt;
	}&lt;br&gt;
&lt;br&gt;
ul {&lt;br&gt;
	margin-left: 14px;&lt;br&gt;
	}&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
Since most CSS problems are caused by Internet Explorer (assuming you&apos;re not coding for Netscape 4), I&apos;ve also taken to having hack-free CSS in my main style sheet and using &lt;a href=&quot;http://www.quirksmode.org/css/condcom.html&quot;&gt;conditional comments&lt;/a&gt; to put all my IE fixes in an IE-only style sheet.&lt;br&gt;
&lt;br&gt;
The order of rules is especially important &lt;a href=&quot;http://www.meyerweb.com/eric/css/link-specificity.html&quot;&gt;for links&lt;/a&gt;; the recommended order is link, visited, hover, and active. I usually put my links at the bottom of the style sheet, with the default link styles before custom links, to control the link styles more easily.&lt;br&gt;
&lt;br&gt;
Grouping definitions, like I did with &lt;code&gt;p,dd,ol,ul&lt;/code&gt; in my example, helps keep the formatting consistent and the style sheet easier to maintain.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2005:site.21312-344780</guid>
		<pubDate>Sun, 17 Jul 2005 12:11:02 -0800</pubDate>
		<dc:creator>kirkaracha</dc:creator>
	</item><item>
		<title>By: gentle</title>
		<link>http://ask.metafilter.com/21312/CSS-organisation-tips#344822</link>	
		<description>I like to divide styles into multiple stylesheets and make use of the overlaying feature of CSS.&lt;br&gt;
&lt;br&gt;
To start, one core stylesheet covering generic element redefinitions -- ie., no classes and no element IDs -- such as:&lt;br&gt;
&lt;br&gt;
&lt;tt&gt;* { margin: 0; padding: 0; }&lt;br&gt;
body { font-family: Verdana; }&lt;br&gt;
table { border-spacing: 0; border-collapse: collapse; }&lt;/tt&gt;&lt;br&gt;
&lt;br&gt;
Then a separate stylesheet covering site-wide settings, ie. elements generally prevalent on all pages, such as navigation.&lt;br&gt;
&lt;br&gt;
Then again a stylesheet for individual pages or page types. For example, I might have a page containing a complex form which requires a bunch of CSS rules which only apply to that one page; thus I move these rules into a separate CSS file that is included by just that one page -- why burden the whole site with those rules?&lt;br&gt;
&lt;br&gt;
The most frequent type of annoyance when developing CSS is misapplying the style, because you misspelled a class name or got the selector wrong, and sometimes such changes affect elements of the page that you aren&apos;t working on; scoping the CSS like this prevents &quot;spillage&quot; and makes the separation clean.&lt;br&gt;
&lt;br&gt;
Stylesheet separation also helps against CSS cruft -- old rules that you didn&apos;t delete when you deleted the page elements they referred to.&lt;br&gt;
&lt;br&gt;
Sometimes it also makes sense to have section-specific stylesheets that do all of the above; for example, if you have a section of administrative pages, instead of declaring something like &lt;tt&gt;&amp;lt;body class=&quot;adminSection&quot;&amp;gt;&lt;/tt&gt;, just include a separate core stylesheet after the main core stylesheet.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2005:site.21312-344822</guid>
		<pubDate>Sun, 17 Jul 2005 13:21:55 -0800</pubDate>
		<dc:creator>gentle</dc:creator>
	</item><item>
		<title>By: Fezboy!</title>
		<link>http://ask.metafilter.com/21312/CSS-organisation-tips#344891</link>	
		<description>I generally use three CSS files for every page.  The first links to a baselining stylesheet much like kirkaracha.  The second applies all of the positioning, floating, margins, and padding.  Back when I still gave a damn about supporting dead browsers (IE5.x, NS4.x, MacIE5.x) I often had two or three different CSS files with specific browser-based rules.  I&apos;ve got fewer worries these days since other requirements of the project I&apos;m working on demand IE6/Moz/Safari2/Opera8 so I can assume decent CSS/DOM support.  The third provides all of the decorative rules like fonts, colors, borders, etc.  This basically allows me to build a structure and then skin it differently.  Pages are named by some convention&#8212;generally baseline.css, siteSection_layout.css, and siteSection_display.css.&lt;br&gt;
&lt;br&gt;
In-sheet organization is basic elements first, general classes second, specific id-related rules third.  Each group of styles is put in alphabetical order unless this causes problems.  If this happens I make judicious use of comments.  Also, most of my structural CSS looks like:&lt;br&gt;
&lt;code&gt;element#id {&lt;br&gt;
     attribute:value;&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
parentElement element#id {&lt;br&gt;
     attribute:value;&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
parentElement * element#id {&lt;br&gt;
     attribute:value;&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
parentElement&amp;gt;*element#id {&lt;br&gt;
     attribute:value;&lt;br&gt;
}&lt;br&gt;
etc.&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
so I can use some combination of selections so browser support determines which rules get applied&#8212;thus avoiding unreliable javascript/UA reading tricks.  These are generally commented so I know the reason behind each iteration.&lt;br&gt;
&lt;br&gt;
Great question and good answers all!</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2005:site.21312-344891</guid>
		<pubDate>Sun, 17 Jul 2005 15:45:26 -0800</pubDate>
		<dc:creator>Fezboy!</dc:creator>
	</item><item>
		<title>By: amestoy</title>
		<link>http://ask.metafilter.com/21312/CSS-organisation-tips#345115</link>	
		<description>Thanks all. I particularly like malevolent&apos;s technique of using descendent selectors instead of section comments, it makes each rule&apos;s specificity very clear as well as providing a grouping mechanism. Like gentle I also use page-specific sheets which again help to clarify specificity and reduce redundant styles.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2005:site.21312-345115</guid>
		<pubDate>Mon, 18 Jul 2005 08:19:43 -0800</pubDate>
		<dc:creator>amestoy</dc:creator>
	</item><item>
		<title>By: amestoy</title>
		<link>http://ask.metafilter.com/21312/CSS-organisation-tips#345694</link>	
		<description>Coincidentally Digital Web Magazine has just published &lt;a href=&quot;http://www.digital-web.com/articles/architecting_css/&quot;&gt;this article&lt;/a&gt; which discusses CSS organisation issues. I like the recommendation to always order attributes alphabetically to avoid repeating them inadvertantly.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2005:site.21312-345694</guid>
		<pubDate>Tue, 19 Jul 2005 01:53:26 -0800</pubDate>
		<dc:creator>amestoy</dc:creator>
	</item>
	</channel>
</rss>
