<?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>Six Revisions &#187; CSS Tips</title>
	<atom:link href="http://sixrevisions.com/category/css/css-tips/feed/" rel="self" type="application/rss+xml" />
	<link>http://sixrevisions.com</link>
	<description></description>
	<lastBuildDate>Fri, 18 May 2012 00:25:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>CSS Tip #2: Structural Naming Convention in CSS</title>
		<link>http://sixrevisions.com/css/css-tips/css-tip-2-structural-naming-convention-in-css/</link>
		<comments>http://sixrevisions.com/css/css-tips/css-tip-2-structural-naming-convention-in-css/#comments</comments>
		<pubDate>Thu, 04 Dec 2008 05:25:05 +0000</pubDate>
		<dc:creator>Jacob Gube</dc:creator>
				<category><![CDATA[CSS Tips]]></category>

		<guid isPermaLink="false">http://sixrevisions.com/?p=242</guid>
		<description><![CDATA[<a href='http://rss.buysellads.com/click.php?z=1259902&k=6989dd4b5220d0b14530453de7387991&a=242&c=1015884517' target='_blank'><img src='http://rss.buysellads.com/img.php?z=1259902&k=6989dd4b5220d0b14530453de7387991&a=242&c=1015884517' border='0' alt='' /></a><p><a href='http://buysellads.com/buy/sitedetails/pubkey/6989dd4b5220d0b14530453de7387991/zone/1259902' target='_blank'>Advertise here with BSA</a></p><br />Structural naming convention – in essence – just means that you name (by assigning a class and/or id attribute to them) elements by describing what they are, and not where they are or how the look.  Its counterpart is called presentational naming which describes the location and/or appearance of web page elements. This CSS tip [...]]]></description>
			<content:encoded><![CDATA[<a href='http://rss.buysellads.com/click.php?z=1259902&k=6989dd4b5220d0b14530453de7387991&a=242&c=1367872787' target='_blank'><img src='http://rss.buysellads.com/img.php?z=1259902&k=6989dd4b5220d0b14530453de7387991&a=242&c=1367872787' border='0' alt='' /></a><p><a href='http://buysellads.com/buy/sitedetails/pubkey/6989dd4b5220d0b14530453de7387991/zone/1259902' target='_blank'>Advertise here with BSA</a></p><br /><p><em>Structural naming convention</em> – in essence – just means that  you name (by assigning a class and/or id attribute to them) elements by  describing <em>what they are</em>, and not <em>where they are</em> or <em>how the look</em>.  Its counterpart is called presentational  naming which describes the <em>location and/or appearance</em> of web page elements.</p>
<p><img src="http://images.sixrevisions.com/2008/12/03-01_leading_image.jpg" alt="Leading image" width="550" height="240" /><br />
<span id="more-242"></span></p>
<p>This CSS tip discusses the <strong>concept of structural naming  conventions</strong>, the <strong>benefits of using this convention</strong>, and shares <strong>some guidelines</strong> on practical applications of structural naming conventions.</p>
<h3>Let&#8217;s start with a presentational naming example</h3>
<p>To illustrate by way of example, take a look at Example 1  which uses a presentational naming convention.</p>
<p><a href="http://sixrevisions.com/demo/structural_naming/example1.html">Example 1</a>:  A presentational layout.</p>
<p><img src="http://images.sixrevisions.com/2008/12/03-02_example_1.png" alt="Example 1 - screen shot." width="550" height="240" /></p>
<h3>What&#8217;s wrong about the layout?</h3>
<p>There are <em>two</em> major fundamental flaws in using a naming  convention such as shown in <a href="http://sixrevisions.com/demo/structural_naming/example1.html">Example 1</a>.</p>
<p>First, it makes it hard to <em>move things around</em> without  affecting the accuracy of your markup.</p>
<p>Although the <code>#top-div</code> and <code>#bottom-div</code> will most likely stay  in place, a design decision to put the secondary content (<code>#right-col</code>) to the  right of the main content area (<code>#left-col</code>) completely <em>invalidates</em> the  document&#8217;s model.</p>
<p>Secondly, the names don&#8217;t help describe <em>what the elements  are</em> – what <em>they&#8217;re for</em> and <em>what they do</em> as part of the overall document.</p>
<p>For example, the link with the class <code>.red-link</code> in <a href="http://sixrevisions.com/demo/structural_naming/example1.html">Example 1</a> describes the color of the link, but not what it&#8217;s for.</p>
<h3>A realistic example</h3>
<p>Let&#8217;s pretend I hired a new developer in my team – let&#8217;s  call him <em>Dave Newbie</em>. I&#8217;ve given Dave the task of updating a website that uses  a <em>presentational</em> naming convention instead of a <em>structural</em> naming convention.</p>
<p>The site&#8217;s CSS is much like <a href="http://sixrevisions.com/demo/structural_naming/example1.html">Example 1</a>,  but instead of only 13 lines of declarations, it&#8217;s 500 lines (single-spaced,  single-lined, shorthand notation).</p>
<p>I didn&#8217;t give Dave any other instructions besides updating  the pages and assigning elements the appropriate class or id (I didn&#8217;t comment  my code, because remember &#8211; I like to do things the <em>hard way</em>).</p>
<p>In a web page Dave was tasked to update, he encounters a  special class of links with the name <code>.red-link</code> (as shown in Example 1).</p>
<p><img src="http://images.sixrevisions.com/2008/12/03-03_red-link.png" alt=".red-link example" width="550" height="240" /></p>
<p>Now he&#8217;s scratching his head wondering why these guys have a  class of <code>.red-link</code>…</p>
<p>What if <strong>instead</strong> of <code>.red-link</code>, I named it <code>.external-link</code>?</p>
<p>Dave would know <em>instantly</em> (and if he doesn&#8217;t – then I&#8217;d have to reconsider his employment) that any links that point to another website  gets assigned a link of <code>.red-link</code>.</p>
<p>And that&#8217;s the <em>practical reason</em> for choosing a structural  naming convention instead of a presentational naming convention &#8211; if not for  <em>semantics and best practices</em> – then for helping Dave Newbie know what  particular classes and ids mean, <em>not what they look like or where they are</em> (which he can already see <em>anyways</em> &#8211; granted that he doesn&#8217;t suffer from  dyslexia or particular forms of color-blindness).</p>
<p>Let&#8217;s rework <a href="http://sixrevisions.com/demo/structural_naming/example1.html">Example 1</a> to reflect a (sort of) structural naming convention.</p>
<p><a href="http://sixrevisions.com/demo/structural_naming/example2.html">Example 2</a>:  A structural naming convention.</p>
<p><img src="http://images.sixrevisions.com/2008/12/03-04_example_2.png" alt="Example 2 illustration" width="550" height="240" /></p>
<p>In <a href="http://sixrevisions.com/demo/structural_naming/example2.html">Example 2</a>,  I&#8217;ve renamed the classes and ids to <em>structurally-descriptive</em> names.</p>
<p><code>#top-div</code> has become <code>#header</code>, <code>#left-col</code> (short for left column) has been renamed to <code>#main-content</code>, and so on. That&#8217;s much better and more intuitive.</p>
<h3>Wait a minute!</h3>
<p>After looking at the example, some of you may be saying &#8220;<em>Wait  a minute</em> Jacob, aren&#8217;t <code>#header</code> and <code>#footer</code> <em>presentational descriptors</em>?&#8221; -  some might even modify this question with an  abbreviated explicitive and exclamation point like &#8220;…WTF!&#8221;, and some may go  further with &#8220;WTF n00b!!&#8221;.</p>
<p><em>Yes</em>, indeed you&#8217;re (mostly) <em>right</em>.</p>
<p>But now I ask you this: <em>without</em> any additional information –  what does <code>#header</code> and <code>#footer</code> <em>mean to you</em>?</p>
<p>Some of the responses might be:</p>
<h4><code>#header</code> is for&#8230;</h4>
<ul>
<li>logo/branding</li>
<li>where your primary navigation is</li>
<li>where the tagline of your website is,  etc.</li>
</ul>
<h4><code>#footer</code> is for&#8230;</h4>
<ul>
<li>Copyright information</li>
<li>a repeat of important page links</li>
<li>auxiliary information or additional site features</li>
</ul>
<p><em>Without telling you</em> (or Dave Newbie for that matter), what  they mean <em>to me</em>, you already know what they are for and what they <em>probably</em> mean.</p>
<p>That&#8217;s because names such as <code>#header</code>, <code>#footer</code>, and <code>#sidebar</code> are  <strong>well-established</strong>.</p>
<p>In a survey of websites of some web professionals, Andy  Clarke lists the naming convention used for the structure of these sites, <a title="Naming conventions table" href="http://www.stuffandnonsense.co.uk/archives/naming_conventions_table.html">check it out here</a>.</p>
<p>You can see in Andy Clarke&#8217;s survey that <code>#header</code> and <code>#footer</code> are staples, and are  used the majority of time. So they&#8217;re <em>instantly</em> recognizable.</p>
<p>We can follow a structural naming convention <em>blindly</em> by  instead using <code>#branding</code> for <code>#header</code> and <code>#siteinfo</code> for <code>#footer</code> – but at the end  of the day, I chose to bend the &#8220;rules&#8221; for the <em>purpose of practicality</em>.</p>
<p><code>#header</code> and <code>#footer</code> <em>still describe</em> the <strong>purpose</strong> and <strong>the structure</strong> of those particular elements in the document, <em>exactly</em> like <code>#branding</code> and  #siteinfo does.</p>
<p>In short, Dave Newbie won&#8217;t be knocking on my door at 3:00AM  in the morning asking me what <code>#branding</code> means so that he can meet his deadline (and Dave, <em>please</em> call or text next time, don&#8217;t just show up in my front door steps).</p>
<p>But for those who are unwilling to compromise, let&#8217;s rework <a href="http://sixrevisions.com/demo/structural_naming/example2.html">Example 2</a> to a <em>strictly</em> structurally-named example.</p>
<p><a href="http://sixrevisions.com/demo/structural_naming/example3.html">Example 3</a>:  Really using structural naming conventions.</p>
<p><a href="http://sixrevisions.com/demo/structural_naming/example3.html">Example 3</a> is fully-structural in naming convention. It describes what the div&#8217;s and  other elements are for, instead of where they are or how they look. I&#8217;ve used Andy  Clarke&#8217;s suggestions in <a title="What's in a name (pt2)" href="http://www.stuffandnonsense.co.uk/archives/whats_in_a_name_pt2.html">an article he wrote a ways back</a>.</p>
<h3>A few guidelines</h3>
<p>Here are a few guidelines to help you name your elements  <em>structurally</em>, and <em>these</em> are just <em>that</em> – <em>guidelines</em>. In the end, you have to use  what&#8217;s best for you and the project at hand.</p>
<h4>1. When assigning a class or id, ask yourself &#8220;What is this  element for?&#8221;</h4>
<p>For example, if you have a span class that&#8217;s meant for  captions, you might call it <code>.caption</code> or <code>.figure-caption</code> instead of  <code>.smaller-text</code>.</p>
<p>If a particular group of images are banner advertisements, you  might want to call the class <code>.banner</code> or <code>.ad-banner</code> instead of <code>.sidebar-images</code> (since they may change locations).</p>
<h4>2. Avoid using names that rely on locational or visual aspects  of the particular element</h4>
<p>In <a href="http://sixrevisions.com/demo/structural_naming/example1.html">Example 1</a>,  we used <code>.red-link</code> for links that are <em>red</em>, and <code>#left-col</code> for the column on the  left.</p>
<p>Later on, in <a href="http://sixrevisions.com/demo/structural_naming/example2.html">Example 2</a> and <a href="http://sixrevisions.com/demo/structural_naming/example3.html">Example  3</a>, we changed them to .external-link and .main-content.</p>
<p>The practical reason for doing this is that it keeps your  HTML markup accurate even if &#8211; say &#8211; you change the style of the <code>.red-link</code> class to <em>green</em> or <em>brown</em>.</p>
<p>Of course you can always do a <em>batch find-and-replace</em> if you  have a static site, <em>hunting down</em> <code>.red-link</code> and <em>replacing</em> them with <code>.blue-link</code> in all of your affected HTML documents, but <em>why rely on that</em> when you can <em>avoid  it in the first place</em> with a little forethought.</p>
<p>It also keeps your code (<em>code</em> is used <em>literally</em> here, not to  imply that CSS or HTML is programming &#8211; which they aren&#8217;t) semantic.</p>
<p>You don&#8217;t have to change <code>.red-link</code> in the markup even when  you&#8217;ve changed the value of the color attribute in the stylesheet, but it would  be <em>semantically inaccurate</em> in describing that particular element.</p>
<p>For example, even if it&#8217;s called <code>.red-link</code> and you changed  your style declaration to:</p>
<pre>a.red-link { color:  blue;  }</pre>
<p><code>a</code> elements with the class <code>.red-link</code> will be rendered as <em>blue</em> despite of their class name (at least in most browsers).</p>
<p>But wouldn&#8217;t that be <em>irritating</em>? I know <em>I wouldn&#8217;t be able  to sleep at night</em> knowing that my <code>.red-link</code>&#8216;s are being rendered as blue.</p>
<p>And wouldn&#8217;t that be <em>confusing</em> to Dave Newbie, the new  member of my development team?</p>
<p>If instead of <code>.red-link</code> or <code>.blue-link</code>, I used <code>.external-link</code>, then it wouldn&#8217;t matter if it&#8217;s red, green, blue, or black – it&#8217;ll be  accurate as long as I do <em>indeed</em> use them for <em>external links</em>.</p>
<h4>3. Use names that are intuitive to you</h4>
<p>Earlier, in <a href="http://sixrevisions.com/demo/structural_naming/example2.html">Example 2</a>,  I used <code>#header</code> instead of <code>#branding</code>. The reason is because I feel that <code>#header</code> is <em>more recognizable</em> than <code>#branding</code>. Notice that even though it can be  interpreted as a locational description – <em>I still used it</em>.</p>
<p>I decided to do what&#8217;s best <em>for me</em> and what I think is best  <em>for the people that might be working on the same project</em>. I bent the &#8220;rules&#8221;  (notice that <em>rules</em> are in quotes because these are more like <em>guidelines</em>, not  the law of the land) &#8211; so to speak &#8211; for the purpose of practicality and  general intuitiveness.</p>
<p>Here&#8217;s a good guideline for naming classes and id&#8217;s  <em>intuitively</em>.</p>
<p>Ask yourself, &#8220;<strong>If I asked <em>Dave Newbie</em> what this class (or  id) is for, would he automatically know?</strong>&#8221;</p>
<p>That&#8217;s programming 101, naming variables <em>intuitively</em> so that  <em>other</em> programmers will know what the variable holds (<code>$total</code> instead of <code>$t</code>) –  and that lesson is <strong>applicable to CSS naming conventions</strong>.</p>
<h3>Further reading</h3>
<p>The concept of structural naming <em>isn&#8217;t new</em>, and there have  been wide discussions about the concept. Here, I&#8217;d like to share a few  resources on the topic to help you further explore the concept.</p>
<h4><a href="http://meyerweb.com/eric/thoughts/2004/06/26/structural-naming/">Structural  Naming</a></h4>
<p>In a short post, Eric Meyer discusses his viewpoints on  class and id naming conventions, mentioning <a href="http://www.stuffandnonsense.co.uk/archives/whats_in_a_name_pt2.html">Andy  Clarke&#8217;s viewpoint</a> on the matter.</p>
<h4><a href="http://articles.techrepublic.com.com/5100-10878_11-5286783.html">Standardizing  CSS class and id names</a></h4>
<p>Michael Meadhra discusses presentational naming conventions  and structural naming conventions.</p>
<h4><a href="http://www.digital-web.com/articles/build_for_the_future_bend_dont_break/">Build  for the Future: Bend, Don&#8217;t Break</a></h4>
<p>Garret Dimon discusses the foundations of creating a  flexible and adaptable website that&#8217;s always prepared for changes in the  future. He also mentions how HTML markup is the foundation of a website, citing  names like <code>left_bar</code> can quickly be outdated in a design change.</p>
<h3>About the CSS Tips series</h3>
<p>The <strong>CSS Tips</strong> series is a group of articles on Six Revisions  that focus on a particular CSS tip, concept, or best practice. In each article,  I&#8217;ll deconstruct a particular tip/standard/best practice and provide the  context, benefits, and disadvantages of each.</p>
<p>I believe in learning both <em>theory</em> and <em>practice</em>, as well as  striking a balance between <em>strict</em>, <em>uncompromising standards</em> and <em>practicality</em>,  so you&#8217;ll get a chance to learn the way people <em>generally do it</em>, and why you  <em>shouldn&#8217;t necessarily follow them blindly</em>.</p>
<p>I&#8217;ll present each CSS tip as comprehensively as I can, but <strong>I  depend on you</strong> to <em>correct me if I&#8217;m wrong</em>,<em> expound on things I skimmed over</em>,  <em>clarify things that may be confusing to our fellow beginning developers</em>, and  <em>provide your own input on the subject</em> – so I highly encourage <strong>you</strong> to<strong> contribute  in the comments</strong>.</p>
<p>To see all the CSS Tips articles thus far, you can go to the <a href="http://sixrevisions.com/css/">CSS category</a>.</p>
<h3>Related content</h3>
<ul>
<li><a href="http://sixrevisions.com/css/innovative-and-experimental-css-examples-and-techniques/">Innovative (and Experimental) CSS Examples and Techniques</a></li>
<li><a href="http://sixrevisions.com/css/css_techniques_charting_data/">8 CSS Techniques for Charting Data</a></li>
<li><a href="http://sixrevisions.com/css/20_websites_learn_master_css/">20 Websites To Help You Learn and Master CSS</a></li>
<li><a href="http://sixrevisions.com/css/css_code_optimization_formatting_validation/">Web-Based Tools for Optimizing, Formatting and Checking CSS</a></li>
<li><a href="http://sixrevisions.com/css/30_css_techniques_examples/">30 Exceptional CSS Techniques and Examples</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://sixrevisions.com/css/css-tips/css-tip-2-structural-naming-convention-in-css/feed/</wfw:commentRss>
		<slash:comments>31</slash:comments>
		</item>
		<item>
		<title>CSS Tip #1: Resetting Your Styles with CSS Reset</title>
		<link>http://sixrevisions.com/css/css-tips/css-tip-1-resetting-your-styles-with-css-reset/</link>
		<comments>http://sixrevisions.com/css/css-tips/css-tip-1-resetting-your-styles-with-css-reset/#comments</comments>
		<pubDate>Tue, 18 Nov 2008 05:22:19 +0000</pubDate>
		<dc:creator>Jacob Gube</dc:creator>
				<category><![CDATA[CSS Tips]]></category>

		<guid isPermaLink="false">http://sixrevisions.com/?p=204</guid>
		<description><![CDATA[<a href='http://rss.buysellads.com/click.php?z=1259902&k=6989dd4b5220d0b14530453de7387991&a=204&c=1817483690' target='_blank'><img src='http://rss.buysellads.com/img.php?z=1259902&k=6989dd4b5220d0b14530453de7387991&a=204&c=1817483690' border='0' alt='' /></a><p><a href='http://buysellads.com/buy/sitedetails/pubkey/6989dd4b5220d0b14530453de7387991/zone/1259902' target='_blank'>Advertise here with BSA</a></p><br />This is the first part of a series of articles that will discuss a particular CSS best practice or tip. I&#8217;ll be covering a mixture of topics that deals with CSS best practices, performance optimization, and tips and tricks to improve your workflow. Today we&#8217;ll be covering the topic of resetting your styles. Resetting your [...]]]></description>
			<content:encoded><![CDATA[<a href='http://rss.buysellads.com/click.php?z=1259902&k=6989dd4b5220d0b14530453de7387991&a=204&c=2024791146' target='_blank'><img src='http://rss.buysellads.com/img.php?z=1259902&k=6989dd4b5220d0b14530453de7387991&a=204&c=2024791146' border='0' alt='' /></a><p><a href='http://buysellads.com/buy/sitedetails/pubkey/6989dd4b5220d0b14530453de7387991/zone/1259902' target='_blank'>Advertise here with BSA</a></p><br /><p>This is the first part of a series of articles that will  discuss a particular CSS best practice or tip. I&#8217;ll be covering a mixture of  topics that deals with CSS best practices, performance optimization, and tips  and tricks to improve your workflow.</p>
<p>Today we&#8217;ll be covering the topic of resetting your styles.</p>
<p><img src="http://images.sixrevisions.com/2008/11/18-01_css_tip_1_intro.jpg" alt="CSS Tip #1: Resetting Your Styles with CSS Reset" width="550" height="300" /></p>
<p><span id="more-204"></span></p>
<p>Resetting  your styles, commonly referred to as <em>CSS  Reset</em> or <em>Reset CSS</em> is the process  of resetting (or more accurately &#8211; <em>setting</em>)  the styles of all elements to a baseline value so that you avoid cross-browser  differences due to their built-in default style settings. By resetting your  styles, you avoid defaulting to the browser&#8217;s built-in styles, which differs  from browser to browser.</p>
<h3>CSS Reset avoids browser inconsistencies</h3>
<p>For example, say you use an anchor tag <code><code>&lt;a&gt;</code></code> in your  HTML document. Usually, browsers like Internet Explorer and Firefox will render  it as <em>blue</em> and <em>underlined</em>.</p>
<p>But five years from now, someone decides to release a new  browser (let&#8217;s call it <em>UltraBrowser</em>)  and they decide that they don&#8217;t like blue, underlined links – so instead they  set the default style of <code>&lt;a&gt;</code> tags to <em>red</em> and <em>boldfaced</em>. If you always set a  baseline value for your <code>&lt;a&gt;</code> elements, then you&#8217;re guaranteed that it will  always be the same, regardless of what UltraBrowser thinks <code>&lt;a&gt;</code> elements  should look like.</p>
<h3>A simple example</h3>
<p><a href="http://sixrevisions.com/demo/reset_styles/example1.html"><strong>Example 1</strong></a>: How paragraph tags are rendered by default.</p>
<p>In Example 1, I&#8217;ve placed three unstyled paragraphs  <code>&lt;p&gt;</code> inside a container <code>&lt;div&gt;</code> (I gave the container div a blue  background and orange border to highlight the difference).</p>
<p><img src="http://images.sixrevisions.com/2008/11/18-02_css_example.png" alt="How Firefox and Internet Explorer renders paragraph tags" width="550" height="300" /></p>
<p><em>By default, </em>in<em> Firefox</em>,  you&#8217;ll see that there&#8217;s a space in between the top of the first paragraph and  the top of the container div, and a space between the bottom of the last  paragraph and the bottom of the container div.</p>
<p><em>By default</em>, these spaces <em>don&#8217;t  exist</em> in <em>Internet Explorer</em>.</p>
<p>So which browser is right, Firefox or IE? <em>It doesn&#8217;t matter</em>. What <em>does matter</em> is that the spacing in  between your paragraphs and other elements will look dissimilar if you don&#8217;t  set a style for a paragraph&#8217;s margin and padding.</p>
<p>Of course that&#8217;s a rather simplified example. In practice,  CSS Reset is important in removing inconsistent margins, paddings, line-heights,  and other attributes that can cause your web pages to look differently across various  browsers.</p>
<p>So that&#8217;s the basic theory of resetting your styles which just  means <em>you</em> set your style rules for  all elements to avoid having <em>the browser</em> do it for you. Further down, we&#8217;ll talk about it in practice, but first a  little bit of history on how CSS Reset became a standard practice for modern  web developers.</p>
<h3>A reset to where it all started&#8230;</h3>
<p>The concept of CSS Reset was first discussed formally way  back when dinosaurs still roamed the internet (2004 to be exact) by <a href="http://leftjustified.net/about.php">Andrew Krespanis</a>. In <a href="http://leftjustified.net/journal/2004/10/07/css-negotiation/">his article</a>,  he suggests using the universal selector (*) at the beginning of your CSS file to  select all elements and give them 0 values for margin and padding, like so:</p>
<pre>* {
  margin: 0;
  padding: 0;
}</pre>
<p>The universal selector acts like a <em>wildcard search</em>, similar to <a href="http://en.wikipedia.org/wiki/Regular_expression_examples">regular  expression</a> matching in programming. Since in this case, the * isn&#8217;t  preceded by another selector, all elements (in theory – <a title="Universal Selector discussion on SitePoint" href="http://reference.sitepoint.com/css/universalselector">some browsers don&#8217;t fully  support it</a>) is a match and therefore all margins and paddings of all  elements are removed (so we avoid the spacing differences shown in Example 1).</p>
<p>Applying the universal selector margin/padding reset to our  earlier example, we now remove all inconsistent spacing between all browsers  (in other words, we don&#8217;t make the browsers think for us, we show them who&#8217;s  boss).</p>
<p><a href="http://sixrevisions.com/demo/reset_styles/example2.html"><strong>Example 2</strong></a>: Applying the universal selector margin/padding  reset</p>
<p>But now we don&#8217;t have <em>any</em> spacing in between paragraphs, so somewhere below our universal selector reset,  we&#8217;ll declare the way <em>we</em> want our  paragraphs to look like. You can do it a number of ways – you <em>can </em>put margins  (or padding) at the beginning or top of your paragraphs, or both. You can use  ems as your units or pixels or percentages.</p>
<p>What&#8217;s important is that <em>we</em> choose the way the browser will render it. For our example, I chose to add  margins (instead of padding) both at the top of the paragraphs and at the  bottom &#8211; but that&#8217;s my choice, you may want to do it differently.</p>
<p>Here&#8217;s what I used:</p>
<pre>* { margin:0; padding:0; }
p { margin:5px 0 10px 0; }</pre>
<p><a href="http://sixrevisions.com/demo/reset_styles/example3.html"><strong>Example 3</strong></a>: Declaring a style rule after the universal  selector.</p>
<blockquote><p><strong>Note:</strong> The example I used for discussion is a simplified  example. If you <em>only used paragraphs</em> for your web pages and no other elements, you wouldn&#8217;t want to reset your  margins to 0 using the universal selector only to declare a style rule right  after it for your paragraph. We&#8217;ll discuss this more fully along with other  best practices later on down the page.</p></blockquote>
<p>Shortly thereafter – CSS guru <a title="Bio page of Eric A. Meyer" href="http://meyerweb.com/eric/">Eric Meyer</a> further built on the concept of resetting margins and paddings. In <a title="Eric's Archived Thoughts: Really Undoing html.css" href="http://meyerweb.com/eric/thoughts/2004/09/15/emreallyem-undoing-htmlcss/">Eric Meyer&#8217;s  exploration</a>, he discusses <a title="Undoing html.css and using debug scaffolding" href="http://tantek.com/log/2004/09.html#d06t2354">Tanek&#8217;s work undoing  default HTML styles</a> (which he called <a title="undohtml.css source code" href="http://tantek.com/log/2004/undohtml.css">undohtml.css</a>)  which <em>not only</em> resets margins and padding,  but also other attributes like line-heights, font styles, and list styles (some  browsers use different bullets for unordered list items).</p>
<p>After many iterations and refinements, we come to a  wonderful solution called <del datetime="2008-11-19T16:45:38+00:00"><a title="Eric's Archived Thoughts: Reset Reloaded" href="http://meyerweb.com/eric/thoughts/2007/05/01/reset-reloaded/">CSS Reset Reloaded</a></del> <a href="http://meyerweb.com/eric/tools/css/reset/index.html">CSS Reset</a>, which  not only makes this CSS reset method more accurate than the universal selector  method by using higher specificity by naming all possible HTML tags (because  the universal selector fails to apply the reset to all HTML tags), but also  sets default values for troublesome elements like tables (in which the  border-collapse attribute isn&#8217;t rendered consistently across browsers).</p>
<p>Of course, there are other methods of resetting your CSS (such  as Yahoo!&#8217;s <a href="http://developer.yahoo.com/yui/reset/">YUI Reset CSS</a> which I currently use on Six Revisions), and you can roll your own based on  your preference and project needs.</p>
<p>Now let&#8217;s go through some tips and best practices when  applying a CSS Reset solution to  your  own projects.</p>
<h3>Applying CSS Reset: tips and best practices</h3>
<h4>1. Start by deciding <em>exactly</em> how you&#8217;ll reset your styles</h4>
<p>Above, I&#8217;ve shown you the two extremes of CSS Reset. From a sweet  and simple method using the universal selector (which I don&#8217;t recommend you  using) to a more involved and  complex method with Eric Meyer&#8217;s <a href="http://meyerweb.com/eric/thoughts/2007/05/01/reset-reloaded/">CSS Reset Reloaded</a> (edit: or the more current version, <a href="http://meyerweb.com/eric/tools/css/reset/index.html">Reset CSS)</a>.</p>
<p>I also briefly mentioned the YUI Reset CSS which you can use <a title="Yahoo! UI Library: Reset CSS - Getting Started" href="http://developer.yahoo.com/yui/reset/#start">directly off the YDN so  that you don&#8217;t have to serve it</a>, saving you some server resources when your  web pages are requested. You can also <a title="Weekend Quick Tip: Create Your Own Simple Reset.css File - NETTUTS" href="http://nettuts.com/html-css-techniques/weekend-quick-tip-create-your-own-resetcss-file/">roll  your own</a> and tailor it to your specific needs.</p>
<p>There&#8217;s no pre-defined step-by-step method for determining  the right way of resetting your styles; the important part is that it works to  compliment your own development style and principles.</p>
<p>To help you make your choice, here are a couple of excellent  resources to get you started:</p>
<ul>
<li><a href="http://perishablepress.com/press/2007/10/23/a-killer-collection-of-global-css-reset-styles/">A  Killer Collection of Global CSS Reset Styles</a></li>
<li><a href="http://www.ejeliot.com/blog/85">Less is more &#8211; my  choice of Reset CSS</a> (by Ed Elliot)</li>
</ul>
<h4>2. Your CSS Reset has to be the first thing the browser sees  (duh).</h4>
<p>Resetting your styles after declaring a style rule for an  element will mess you up. You&#8217;ll scratch your head wondering why the margins  you declared for <code>.some-class</code> isn&#8217;t working. Therefore it&#8217;s essential that the  first thing the browser sees is your CSS Reset.</p>
<p>Laugh now, but it&#8217;s <em>a  common mistake</em> amongst rusty veterans and beginning developers.</p>
<blockquote><p><strong>Note:</strong> In case you  fall into the &#8220;people-prone-to-this-common-mistake&#8221; category, here&#8217;s  the reason why it has to be at the very top of your CSS document/s: <em>CSS works on a top-down hierarchy with rules  lower down the CSS document taking precedence if there&#8217;s a  conflicting/redundant style rule declaration</em>.</p></blockquote>
<p>Just to continue beating a dead horse, let&#8217;s explore an  example. I used Eric Meyer&#8217;s <a href="http://meyerweb.com/eric/thoughts/2007/05/01/reset-reloaded/">CSS Reset Reloaded</a> <em>verbatim</em> in the example <em>after</em> declaring a style rule for the  margin of my <code>&lt;p&gt;</code> elements.</p>
<p><a href="http://sixrevisions.com/demo/reset_styles/example4.html"><strong>Example 4</strong></a>: Putting your CSS Reset in the wrong place</p>
<p>I have the style rules at the examples&#8217; HTML document (for  convenience), so that you can view the source and see what I mean.</p>
<p>In essence, what you see is that even though I declared  margins for my <code><code>&lt;p&gt;</code></code> elements, my CSS Reset &#8220;reset&#8221; them to 0  because it takes precedence over my initial style rule declaration.</p>
<h4>3. Have a separate CSS document for your CSS Reset</h4>
<p>I have to mention this tip because it&#8217;s common practice and  one that many people advocate.</p>
<p>I&#8217;m on the <em>One  Big CSS File</em> (of course it varies on a case-by-case basis) camp for page  performance reasons (I&#8217;ll save this discussion for another day, perhaps on  another CSS Tip article), but a common practice is to have <em>a separate CSS document</em> (named something like <em>reset.css</em>) that you  can reuse throughout your projects. This helps you keep your style rules  organized and modular, but more importantly, it makes it easier to change and  tweak your CSS Reset without having to go back to your old projects and  updating it.</p>
<h4>4. Avoid using the universal selector reset</h4>
<p>The universal selector reset is the first true conception (that  I know of at least, so please correct me if I&#8217;m wrong) of resetting your  styles, but it has many shortcomings and browser inconsistencies (which is what  <em>we&#8217;re trying to get rid of</em> in the first place) that make it a poor choice.</p>
<p>I&#8217;ve already mentioned that IE doesn&#8217;t apply and support it  as intended; it doesn&#8217;t cover all your bases and you should only use it for  simple, short, static, and predictable web pages (if you really have to use it).</p>
<p>This tip especially holds true when you distribute a  &#8220;one-size-fits-all&#8221; solution like a content management system theme  which will be used and hacked in unpredictable ways. Using a solid foundation  at the get-go &#8211; an extensive CSS Reset method &#8211; ensures that you&#8217;re truly  resetting your styles and it&#8217;s worth the added bytes in your CSS document.</p>
<h4>5. Avoid redundancy with your CSS Reset and subsequent style  declarations</h4>
<p>Another reason I don&#8217;t like having a separate stylesheet for  my CSS Reset is that it can cause redundancies with other style  rules after it. It&#8217;s good practice not to repeat your styles, and although sometimes it  can&#8217;t be avoided (because you&#8217;re lazy <em>like me</em>), you should make an effort to try. Going back to Eric Meyer&#8217;s CSS  Reset Reloaded set of rules, he gives default values for <code>line-height</code>, <code>color</code>,  and <code>background</code> of the body element like so:</p>
<pre>body {
  line-height: 1;
  color: black;
  background: white;
  }</pre>
<p>If you already know that the body style attributes will be (for  example):</p>
<ul>
<li>background-color: #cccccc</li>
<li>color: #996633</li>
<li>and you want to tile a background image horizontally</li>
</ul>
<p>there&#8217;s no sense declaring another CSS selector for the body  element later on the document – you should replace that part of your CSS reset  to the following:</p>
<pre>body {
  line-height: 1;

  color: #996633

  background:#ccc url(your-tiled-image.gif) repeat-x top left;
  }</pre>
<p><em>Don&#8217;t be afraid to use  your own judgment</em>. Tweak, re-structure, delete, and add things as you see  fit and as it pertains to your particular case.</p>
<p>Eric Meyer echoes this in his discussion of CSS Reset  Reloaded with the following statement:</p>
<blockquote><p>[…] That’s much of the point here:  that this is not a case of &#8220;everyone must use these styles in a certain  way without alteration&#8221;.</p></blockquote>
<h3>Further Reading</h3>
<p>Here are a few excellent resources that I recommend you read on  the topic of resetting your styles.</p>
<h4><a href="http://www.mail-archive.com/wsg@webstandardsgroup.org/msg09417.html">[WSG]  Zeroing default padding/margin</a></h4>
<p>Probably one of the first threads that discuss the universal  selector reset on the Web Standards Group mailing list.</p>
<h4><a href="http://meyerweb.com/eric/articles/webrev/200006a.html">Universal Selector</a></h4>
<p>Eric Meyer discusses how the universal selector works.</p>
<h4><a href="http://snook.ca/archives/html_and_css/no_css_reset/">No  CSS Reset</a></h4>
<p>Johnathan Snook discusses why he doesn&#8217;t reset his styles; a  great counter-argument from one of the most respected web developers/designers  out there.</p>
<h4><a href="http://mondaybynoon.com/2008/04/21/why-i-like-and-use-reset-css/">Why I  Like (and Use) Reset CSS</a></h4>
<p>A short and sweet discussion of why resetting CSS is a great  idea.</p>
<h4><a href="http://devkick.com/lab/tripoli/">Tripoli &#8211; a CSS  standard for HTML rendering</a></h4>
<p>Tripoli  is another popular CSS Reset option that has several versions so that you can  use the one most appropriate for your project.</p>
<h3>About the CSS Tips series</h3>
<p>The <em>CSS Tips</em> series is a group of articles that focus on one particular CSS tip or best  practice. In each article, I&#8217;ll deconstruct a particular tip/standard/best  practice and provide the context, benefits, and disadvantages of each.</p>
<p>I believe in learning both <em>theory</em> and <em>practice</em>, as  well as striking a balance between strict, uncompromising standards <em>and </em>practicality, so you&#8217;ll get a chance to learn the <em>way people generally do it</em>, and why <em>you shouldn&#8217;t necessarily follow them blindly</em>.</p>
<p>I&#8217;ll present each CSS tip as comprehensively as I can but  I <strong>depend on you</strong> to correct me if I&#8217;m  wrong, expound on things I skimmed over, clarify things that may be confusing  to our fellow beginning developers, and provide your own input on the subject – <strong>so I highly encourage you to contribute  in the comments</strong>.</p>
<p>To see all the CSS Tips articles thus far, you can go  to the <a href="http://sixrevisions.com/category/css/css-tips/">CSS category</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://sixrevisions.com/css/css-tips/css-tip-1-resetting-your-styles-with-css-reset/feed/</wfw:commentRss>
		<slash:comments>72</slash:comments>
		</item>
	</channel>
</rss>

