<?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>The Fruits of my Labour &#187; CSS</title>
	<atom:link href="http://www.toao.net/web-programming/css/feed" rel="self" type="application/rss+xml" />
	<link>http://www.toao.net</link>
	<description>by Mango</description>
	<lastBuildDate>Sun, 18 Jul 2010 21:44:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Dynamically Add a CSS Class using Javascript</title>
		<link>http://www.toao.net/11-dynamically-add-a-css-class-using-javascript</link>
		<comments>http://www.toao.net/11-dynamically-add-a-css-class-using-javascript#comments</comments>
		<pubDate>Thu, 10 Aug 2006 19:42:30 +0000</pubDate>
		<dc:creator>Mango</dc:creator>
				<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://www.toao.net/11/dynamically-add-a-css-class-using-javascript/</guid>
		<description><![CDATA[I was writing a module for a webapp today and was thinking how cool it would be if I could dynamically add CSS classes using Javascript.&#160; At that particular moment, I had all the classes for all the modules grouped together in one big file, but since sometimes I didn't load all the modules, it [...]]]></description>
			<content:encoded><![CDATA[<br />I was writing a module for a webapp today and was thinking how cool it would be if I could dynamically add CSS classes using Javascript.&nbsp; At that particular moment, I had all the classes for all the modules grouped together in one big file, but since sometimes I didn't load all the modules, it was inefficient.<br />
<br />
It took me a while to find some examples on doing this, so figured I would post the function I wrote in case anyone else has this same problem.<br />


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> addCSSclass<span style="color: #009900;">&#40;</span>className<span style="color: #339933;">,</span> classRule<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
 <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">all</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  document.<span style="color: #660066;">styleSheets</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">addRule</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.&quot;</span> <span style="color: #339933;">+</span> className<span style="color: #339933;">,</span> classRule<span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  document.<span style="color: #660066;">styleSheets</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">insertRule</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.&quot;</span> <span style="color: #339933;">+</span> className <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; { &quot;</span> <span style="color: #339933;">+</span> classRule <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; }&quot;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
 <span style="color: #009900;">&#125;</span></pre></div></div>
Enjoy!]]></content:encoded>
			<wfw:commentRss>http://www.toao.net/11-dynamically-add-a-css-class-using-javascript/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CSS Media Types</title>
		<link>http://www.toao.net/9-css-media-types</link>
		<comments>http://www.toao.net/9-css-media-types#comments</comments>
		<pubDate>Mon, 19 Jun 2006 04:17:40 +0000</pubDate>
		<dc:creator>Mango</dc:creator>
				<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://www.toao.net/9/css-media-types/</guid>
		<description><![CDATA[One thing that really frustrates me is when I try to print something off a website, and my printer prints three pages of headers, graphics, and menus, and ONE page of what I actually wanted to print.&#160; Some designers have thought ahead and have a link to open their pages in a new window, unformatted, [...]]]></description>
			<content:encoded><![CDATA[<br />One thing that really frustrates me is when I try to print something off a website, and my printer prints three pages of headers, graphics, and menus, and ONE page of what I actually wanted to print.&nbsp; Some designers have thought ahead and have a link to open their pages in a new window, unformatted, but this doesn't always work, especially if the page is, for example, dynamically generated by submitting a form, or the user has a pop-up blocker.&nbsp; Fortunately, there's a really cool CSS technique for making this easier.&nbsp; It lets you use one stylesheet for what your users see on the screen, and a completely different stylesheet for what you print!&nbsp; And it works like a <span style="font-weight: bold">charm!</span><br   />
<br  />
<span id="more-9"></span><br   />
<br />
This technique uses CSS Media Types, or as they're commonly known, @media rules.&nbsp; And the best thing is, @media rules take about two seconds to learn how to use.&nbsp; Here's an example:<br />


<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #a1a100;">@media screen { </span>
 <span style="color: #808080; font-style: italic;">/* This rule says: do not display any elements with the class printonly. */</span>
 <span style="color: #6666ff;">.printonly</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span> 
 <span style="color: #00AA00;">&#125;</span>
<span style="color: #a1a100;">@media print {</span>
 <span style="color: #808080; font-style: italic;">/* This rule says: do not print elements that have the class displayonly. */</span>
 <span style="color: #6666ff;">.displayonly</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
 <span style="color: #00AA00;">&#125;</span></pre></div></div>
If you use this example, just enclose all your headers and whatnot with &lt;div class="displayonly">&lt;/div> and anything that should be printed but not displayed such as a copyright message with &lt;div class="printonly">&lt;/div>. See?! I told you that was easy!]]></content:encoded>
			<wfw:commentRss>http://www.toao.net/9-css-media-types/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
