<?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>Tim Thorp Training &#38; Consulting &#187; CSS</title>
	<atom:link href="http://www.timthorp.com/tag/css/feed" rel="self" type="application/rss+xml" />
	<link>http://www.timthorp.com</link>
	<description>technology made simple.</description>
	<lastBuildDate>Mon, 19 Oct 2009 14:45:17 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>CSS Classes and IDs</title>
		<link>http://www.timthorp.com/webdev/css-classes-and-ids</link>
		<comments>http://www.timthorp.com/webdev/css-classes-and-ids#comments</comments>
		<pubDate>Mon, 18 Feb 2008 12:55:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[webdev]]></category>
		<category><![CDATA[Class]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[ID]]></category>

		<guid isPermaLink="false">http://www.timthorp.com/webdev/css-classes-and-ids</guid>
		<description><![CDATA[I love working with sites designed with CSS and XHTML, but learning and remembering all of the syntax and rules challenges me. When should I use classes and when should I use IDs? What does the HTML and CSS look like when either is chosen?
As a general rule, IDs are meant for elements that happen [...]]]></description>
			<content:encoded><![CDATA[<p>I love working with sites designed with CSS and XHTML, but learning and remembering all of the syntax and rules challenges me. When should I use classes and when should I use IDs? What does the HTML and CSS look like when either is chosen?</p>
<p>As a general rule, IDs are meant for elements that happen once per page and classes are meant for elements that happen several times per page. In a practical sense, I think of classes as things like &#8220;alertbox&#8221;, &#8220;code&#8221;, &#8220;note&#8221;, &#8220;warning&#8221;, &#8220;productname&#8221;, etc.</p>
<p>Whereas with IDs, they are useful for page layout elements like &#8220;header&#8221;, &#8220;body&#8221;, &#8220;wrapper&#8221; and &#8220;box&#8221;. They are also useful for the name of a form and anytime you are integrating with JavaScript, IDs are more useful than classes.</p>
<p>I will approach this issue by using this page as an example. In the following paragraphs, I would like to write some code snippets and have them contained by a light grey box with a black border and courier text. Since an ID is used to identify an individual element on a page and I want to have several code snippets on this page, I should use a CSS class.</p>
<p>Classes</p>
<p>Classes refer to elements which will be used throughout the site and in some cases, several times on one page. I like to think of classes as the stylistic elements that are the pillars of the site.<br />
This is HTML for applying a class to a div:</p>

<div class="wp_codebox"><table><tr id="p65"><td class="code" id="p6code5"><pre class="html" style="font-family:monospace;">&lt;div class=&quot;alert&quot;&gt;</pre></td></tr></table></div>

<p>This is CSS for defining a class:</p>

<div class="wp_codebox"><table><tr id="p66"><td class="code" id="p6code6"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.alert</span> <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">color</span> <span style="color: #00AA00;">:</span> <span style="color: #993333;">red</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>IDs</p>
<p>IDs are used for elements which occur once on a page. Their rules override class rules and can be set up differently on any page, but can only be used once per page. I use them to identify each of my form fields and page divider elements. I could use them for an alert box, as follows, but then I could only have one alert on the page.</p>
<p>This is HTML for applying an ID to a div:</p>

<div class="wp_codebox"><table><tr id="p67"><td class="code" id="p6code7"><pre class="html" style="font-family:monospace;">&lt;div class=&quot;alert&quot;&gt;</pre></td></tr></table></div>

<p>This is CSS for defining an ID:</p>

<div class="wp_codebox"><table><tr id="p68"><td class="code" id="p6code8"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#alert</span> <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">color</span> <span style="color: #00AA00;">:</span> <span style="color: #993333;">red</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.timthorp.com/webdev/css-classes-and-ids/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
