<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Scarf*oo &#187; back to the basics</title>
	<atom:link href="http://scarfoo.com/archives/category/web-development/back-to-the-basics/feed" rel="self" type="application/rss+xml" />
	<link>http://scarfoo.com</link>
	<description>Comfy Web Development With Standards in Mind</description>
	<lastBuildDate>Wed, 19 May 2010 18:59:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>How I Structure My CSS Files</title>
		<link>http://scarfoo.com/archives/152</link>
		<comments>http://scarfoo.com/archives/152#comments</comments>
		<pubDate>Mon, 05 Oct 2009 16:09:43 +0000</pubDate>
		<dc:creator>Damjan Mozetič</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[back to the basics]]></category>
		<category><![CDATA[file organization]]></category>
		<category><![CDATA[structure]]></category>

		<guid isPermaLink="false">http://scarfoo.com/?p=152</guid>
		<description><![CDATA[Let&#8217;s face it, navigating and maintaining large CSS files is no fun. As long as the site is small or if you happen to be in the early stages of development, the CSS file looks manageable, but once you hit the 2k+ line mark, finding what you are looking for can take a while. Not [...]]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s face it, navigating and maintaining large CSS files is no fun. As long as the site is small or if you happen to be in the early stages of development, the CSS file looks manageable, but once you hit the 2k+ line mark, finding what you are looking for can take a while. Not to mention how your team is going to pollute your style.css if the file structure is overly complicated.<br />
<span id="more-152"></span><br />
With some proper CSS file organization, you can wave these problems goodbye. What I am suggesting here is an organization style that has worked for me and my team so far. Let&#8217;s dig into it. </p>
<h3>Structure</h3>
<p><strong>1. Reset</strong><br />
I could as well link one of the many reset.css style sheets, but to save on server requests, I&#8217;ve decided to put the reset styles on the top of my main CSS file.</p>
<p><strong>2. Base</strong><br />
The html, body and defaults for other basic html elements go here. This section is usually pretty minimal, because I like to style elements as they come along in the source. That way I have more control over the styles and less overriding to do later on.</p>
<p><strong>3. Structure</strong><br />
You might opt to let this section go, depending on whether you like to separate the container divs from other styles or not.</p>
<p><strong>4. Header</strong><br />
The definitions for styling the header of your site go here.</p>
<p><strong>5. Content</strong><br />
The definitions for styling the content section of your site go here.</p>
<p><strong>6. Footer</strong><br />
The definitions for styling the footer of your site go here and again you might skip this section if your site has no footer.</p>
<p><strong>7. Navigation</strong><br />
The various menus, breadcrumbs indicator, etc.</p>
<p><strong>8. Modules</strong><br />
I use this section to define the separate modules or blocks used on my site. News, polls, events lists, flickr feeds, quick links, and similar sections are usually defined here.</p>
<p><strong>9. Forms</strong><br />
I like to put all the forms in one place, this proved to be a wise decision over time.</p>
<p><strong>10. Custom Classes</strong><br />
I put here various reusable classes that are frequently shared throughout the site. You might not need this section if your site is a simple one, but when it grows too complex, you might find this section handy.</p>
<p><strong>11. Everything Else</strong><br />
All that you can&#8217;t fit anywhere above. Usually this section only ends up only having a few classes.</p>
<p><strong>12. Print Styles</strong><br />
If you don&#8217;t store your print styles in a separate file, this is the place to define them with a @media print block. You should put this section as the last one, as you potentially want to override any previous CSS declaration.</p>
<h3>Sample</h3>
<p>Here is some code from a sample style file. I&#8217;ve omitted most of the code for simplicity sake, but I&#8217;ve left section and sub-section comments in.</p>
<pre style="height:20em;overflow-y:scroll">
<code style="overflow-y: hidden">/*
 *  Table Of Sections
 *
 *  1. Reset
 *  2. Basic Elements
 *  3. Generic Classes
 *  4. Basic Layout
 *  5. Header
 *  6. Content
 *  7. Sidebar
 *  8. Footer
 *  9. Navigation
 * 10. Forms
 * 11. Modules
 * 12. Print styles
 *
 */

/* Reset  - do NOT modify!
-------------------------------------*/
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, font, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td {
	margin: 0;
	padding: 0;
	border: 0;
	outline: 0;
	font-size: 100%;
	vertical-align: baseline;
	background: transparent;
}
body { line-height: 1; }
ol, ul { list-style: none; }
blockquote, q {	quotes: none; }

/* remember to define focus styles! */
:focus { outline: 0; }

/* remember to highlight inserts somehow! */
ins { text-decoration: none; }
del { text-decoration: line-through; }

/* tables still need 'cellspacing="0"' in the markup */
table {
	border-collapse: collapse;
	border-spacing: 0;
}

/* Basic Elements
-------------------------------------*/
html, body { height: 100%; }

body {
	font-family: helvetica, arial, sans-serif;
	font-size: 62.5%; /* 1em = 10px */
	line-height: 1.5em;
	color: #333;
	background: gray;
}

/* Generic Classes
-------------------------------------*/
/* --- Link list --- */
/* --- News list --- */
/* --- Attachments list --- */
/* --- Links --- */
/* --- Messages --- */
/* --- photo frame &amp; content photos --- */
/* --- Other --- */

/* Basic Layout
-------------------------------------*/

/* Header
-------------------------------------*/

/* Content
-------------------------------------*/
/* external link */
/* --- video --- */
/* --- unsorted list --- */
/* --- numbered list --- */
/* --- tables --- */
/* --- Icons in content --- */
/* --- Search results --- */
/* --- Photogallery --- */
/* --- News --- */

/* Sidebar
-------------------------------------*/

/* Footer
-------------------------------------*/

/* Navigation
-------------------------------------*/
/* --- Breadcrumbs --- */
/* --- Sitemap --- */
/* --- Main Menu --- */

/* Forms
-------------------------------------*/

/* Modules
-------------------------------------*/
/* --- News --- */
/* --- FAQ --- */
/* --- Poll --- */
/* --- Quick links --- */

/* Print styles
-------------------------------------*/
@media print {

	/* Your print styles go here */

}</code>
</pre>
<p>So, here it is &#8211; a nice organized layout for your CSS declarations. I hope you find it useful as much as I did and I&#8217;d love to hear from you if you have any comments or suggestions to improve this.</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://scarfoo.com/archives/130" rel="bookmark" class="crp_title">Quick Tip #1 &#8211; Tame those ems</a></li><li><a href="http://scarfoo.com/archives/11" rel="bookmark" class="crp_title">CSS Tip #1 &#8211; Avoiding Hacks With IE Conditional Comments</a></li><li><a href="http://scarfoo.com/archives/38" rel="bookmark" class="crp_title">Development Diary: 4 Tips on Working With Fluid Layouts</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://scarfoo.com/archives/152/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The CSS Box Model &#8211; Back to The Basics</title>
		<link>http://scarfoo.com/archives/149</link>
		<comments>http://scarfoo.com/archives/149#comments</comments>
		<pubDate>Mon, 20 Apr 2009 21:55:12 +0000</pubDate>
		<dc:creator>Damjan Mozetič</dc:creator>
				<category><![CDATA[back to the basics]]></category>
		<category><![CDATA[box model]]></category>
		<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://scarfoo.com/?p=149</guid>
		<description><![CDATA[Welcome to the second part of the Back to The Basics series of articles here on Scarf*oo. Back to The Basics focuses &#8211; in simple terms &#8211; on the basic stuff every web developer should be familiar with. In the first Back to The Basics article we covered the shorthand CSS notation. Today, we&#8217;ll be [...]]]></description>
			<content:encoded><![CDATA[<p>Welcome to the second part of the Back to The Basics series of articles here on Scarf*oo. Back to The Basics focuses &#8211; in simple terms &#8211; on the basic stuff every web developer should be familiar with. In the <a href="http://scarfoo.com/archives/212">first Back to The Basics article</a> we covered the shorthand CSS notation. Today, we&#8217;ll be looking at the obscure box model and what does it mean to us and how can we manipulate it.</p>
<p><span id="more-149"></span></p>
<h3>The Box Model</h3>
<p>The box model is a term used when referring to the rectangular boxes placed around every element in the page source (source document). It is one of the most basic concepts <strong>every</strong> web designer should know by heart.</p>
<p>The box model is constructed with the following boxes or layers:</p>
<p><img src="http://scarfoo.com/wp-content/uploads/2009/04/box-model.gif" alt="Box Model" title="Box Model" width="323" height="223" class="alignnone size-full wp-image-200" /></p>
<p><b>1. Content</b><br />
The innermost part of the box is the html element itself <em>or content</em>, such as &#8220;&lt;div&gt;&#8221;, &#8220;&lt;p&gt;&#8221;, &#8220;&lt;h1&gt;&#8221;, &#8220;&lt;ul&gt;&#8221; &#8230; etc. The CSS <em>width</em> property defines the width of this element, similar goes for the height.</p>
<pre>
<code>div {
    position: absolute;
    width: 150px; /* set the div element to be 150 pixels wide... */
    height: 40px; /* ... and 40 pixels tall */
}</code>
</pre>
<p><b>2. Padding</b><br />
Next we have the <em>padding</em> property, which is the first layer you&#8217;d encounter going outwards from the actual element covered in the previous point.</p>
<pre>
<code>div {
    position: absolute;
    width: 150px;
    height: 40px;
    padding: 30px 20px 30px 20px; /* add 30 pixels to the top and bottom, and 20 pixels to the left and right padding */
}</code>
</pre>
<p><b>3. Border</b><br />
The middle layer in the box model is the element&#8217;s <em>border</em>. The space used by the border in the box model is the thickness of the border.</p>
<pre>
<code>div {
    position: absolute;
    width: 150px;
    height: 40px;
    padding: 30px 20px 30px 20px;
    border: 1px solid #EFD5B4; /* add a solid 1 pixel thick border with the #EFD5B4 color */
}</code>
</pre>
<p>Above I&#8217;ve used a shorthand notation to define the border&#8217;s <em>thickness</em>, <em>style</em> and <em>color</em>. If you wanted, you could break down each of these three properties into their top, right, bottom and left components, but I&#8217;m not going into that in this tutorial. You can read more on shorthand notations in the first Back to The Basics article, <a href="http://scarfoo.com/archives/212">The Shorthand CSS Notation Explained</a>.</p>
<p><b>4. Margin</b><br />
Then we have the <em>margin</em>, which is the space just outside the border.</p>
<pre>
<code>div {
    position: absolute;
    width: 150px;
    height: 40px;
    padding: 30px 20px 30px 20px;
    border: 1px solid #EFD5B4;
    margin: 30px; /* add a 30 pixels margin around the element */
}</code>
</pre>
<p>Perhaps it is in order to mention that there are some bugs associated with proper margin handling in certain browsers, particularly <abbr title="Microsoft Internet Explorer">IE</abbr> 5 and 6. One of the nastiest bugs is the doubled margin bug, which basically doubles the left and/or right margin if the element is floated. Thankfully this bug has been squashed in <abbr title="Microsoft Internet Explorer">IE</abbr> 7. For a quick fix to this bug, take a look at the last tip in the article <a href="http://scarfoo.com/archives/16">5 CSS Tips to Make IE (You) Happy</a></p>
<p>The sum of the layers above &#8211; left and right margins, border, padding, and the content width &#8211; defines the total box width. Similarly, the sum of the top and bottom margins, border, padding, and the content height defines the total box height. Take in consideration this model when specifying margins, borders and paddings to elements &#8211; basically, everything adds to the width/height of the element.</p>
<p><b>5. Position</b><br />
Lastly we have the position of the element, which is measured from around the bounds of the margin of the element. The position is set with the <em>top</em>, <em>right</em>, <em>bottom</em> and <em>left</em> CSS properties.</p>
<pre>
<code>div {
    position: absolute;
    width: 150px;
    height: 40px;
    padding: 30px 20px 30px 20px;
    border: 1px solid #EFD5B4;
    margin: 30px;
    top: 10px; /* move the element 10 pixels down from the parent element box */
    left: 10px; /* move the element 10 pixels right from the parent element box */
}</code>
</pre>
<h3>Conclusion</h3>
<p><img src="http://scarfoo.com/wp-content/uploads/2009/04/box-model-firebug.gif" alt="Box Model - Firebug" title="Box Model - Firebug" width="320" height="270" class="alignnone size-full wp-image-202" /></p>
<p>I recommend you to install <a href="http://getfirebug.com/">Firebug</a>, a great web development plugin for Firefox. Firebug has a useful box model view represented in the image above.</p>
<p>There are tons of details if you want to dig deeper into the box model. If you want to know more, visit <a href="http://www.w3.org/TR/CSS2/box.html">The Box Model document</a> and the <a href="http://www.w3.org/TR/CSS2/visudet.html">Visual formatting model details document</a>, both located over at <a href="http://www.w3.org/">W3.org</a>.</p>
<p>Thanks for reading!</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://scarfoo.com/archives/212" rel="bookmark" class="crp_title">The Shorthand CSS Notation Explained &#8211; Back to The Basics</a></li><li><a href="http://scarfoo.com/archives/13" rel="bookmark" class="crp_title">CSS Tip #2 &#8211; Accessible Image Replacement Technique</a></li><li><a href="http://scarfoo.com/archives/38" rel="bookmark" class="crp_title">Development Diary: 4 Tips on Working With Fluid Layouts</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://scarfoo.com/archives/149/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The Shorthand CSS Notation Explained &#8211; Back to The Basics</title>
		<link>http://scarfoo.com/archives/212</link>
		<comments>http://scarfoo.com/archives/212#comments</comments>
		<pubDate>Thu, 09 Apr 2009 07:06:36 +0000</pubDate>
		<dc:creator>Damjan Mozetič</dc:creator>
				<category><![CDATA[back to the basics]]></category>
		<category><![CDATA[CSS statements]]></category>
		<category><![CDATA[shorthand notation]]></category>
		<category><![CDATA[shorthand properties]]></category>

		<guid isPermaLink="false">http://scarfoo.com/?p=212</guid>
		<description><![CDATA[Welcome to the first part of the Back to The Basics series of articles here on Scarf*oo. In this series, I&#8217;ll focus &#8211; in simple terms &#8211; on the basic stuff every web developer should be familiar with. Today, we&#8217;ll be looking at the shorthand CSS notation, a quick way to write long CSS statements [...]]]></description>
			<content:encoded><![CDATA[<p>Welcome to the first part of the <em>Back to The Basics</em> series of articles here on Scarf*oo. In this series, I&#8217;ll focus &#8211; in simple terms &#8211; on the basic stuff every web developer should be familiar with. Today, we&#8217;ll be looking at the shorthand CSS notation, a quick way to write long CSS statements in one short line.</p>
<p><span id="more-212"></span></p>
<h3>The Regular Notation</h3>
<p>To begin with, let&#8217;s look at all of the four margin properties written the standard way, long and time-consuming:</p>
<pre>
<code>div {
    margin-top: 10px;
    margin-right: 5px;
    margin-bottom: 10px;
    margin-left: 5px;
}</code>
</pre>
<p>Also, let&#8217;s write down a more complex definition &#8211; an element&#8217;s background property &#8211; in its glorious five components.</p>
<pre>
<code>div {
    background-color: transparent;
    background-image: url(background_image.gif);
    background-repeat: no-repeat;
    background-attachment: fixed;
    background-position: left top;
}</code>
</pre>
<p>While writing the properties the long way is simpler and more descriptive to beginner web developers, you&#8217;ll soon find out that you are writing a lot of redundant code that way. That&#8217;s why there is a standard shorter syntax designed to overcome this issue.</p>
<h3>The Shorthand Notation</h3>
<p>Let&#8217;s try now to write down the margin and background properties the short way to save some space and keyboard mileage.</p>
<pre>
<code>div {
    margin: 10px 5px 10px 5px;
}</code>
</pre>
<p>One thing to learn here is the order of the properties written in the shortened statement above. They always run clockwise, starting with the top property (twelve o&#8217;clock), then right (three o&#8217;clock), then bottom (six o&#8217;clock) and lastly left (nine o&#8217;clock). Be sure to remember that basic rule!</p>
<p>That&#8217;s short, yet we can make that margin definition even shorter, taking advantage of the particular values our properties were set to, like this:</p>
<pre>
<code>div {
    margin: 10px 5px;
}</code>
</pre>
<p>The margin definition above can be shortened like that, because of the matching top &#038; bottom and left &#038; right values. This is valid for any CSS property which has a top, right, bottom and left value, like padding, border, etc.</p>
<p>You could shorten the margin property even further if all of the four margin sides were identical, say 10px like so:</p>
<pre>
<code>div {
    margin: 10px;
}</code>
</pre>
<p>Note, that you can also drop the trailing semicolon from the last property in a block. It&#8217;s not much, but just so you know that you can let it go if you want. Another space saver is to write a one-property block, like the one above in a single line. Let&#8217;s take a look now at our final super-short statement:</p>
<pre>
<code>div { margin: 10px }</code>
</pre>
<p>What about the background property? Using our new knowledge, we can make it really short:</p>
<pre>
<code>div { background: white url(background_image.gif) no-repeat fixed left top }</code>
</pre>
<p>That&#8217;s all I&#8217;ve prepared for you in this first part of <em>Back to The Basics</em>. Make sure to follow this series as I have many things to show you as we move along. </p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://scarfoo.com/archives/149" rel="bookmark" class="crp_title">The CSS Box Model &#8211; Back to The Basics</a></li><li><a href="http://scarfoo.com/archives/13" rel="bookmark" class="crp_title">CSS Tip #2 &#8211; Accessible Image Replacement Technique</a></li><li><a href="http://scarfoo.com/archives/130" rel="bookmark" class="crp_title">Quick Tip #1 &#8211; Tame those ems</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://scarfoo.com/archives/212/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
