<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>CSS Newbie</title>
	
	<link>http://www.cssnewbie.com</link>
	<description>Web Development Tutorials, Tips &amp; Techniques</description>
	<pubDate>Wed, 29 Apr 2009 00:53:43 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/cssnewbie" type="application/rss+xml" /><feedburner:emailServiceId>cssnewbie</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item>
		<title>Using JavaScript to Style Active Navigation Elements</title>
		<link>http://feedproxy.google.com/~r/cssnewbie/~3/WFmpM51NipQ/</link>
		<comments>http://www.cssnewbie.com/using-javascript-to-style-active-navigation-elements/#comments</comments>
		<pubDate>Wed, 29 Apr 2009 00:53:43 +0000</pubDate>
		<dc:creator>Rob Glazebrook</dc:creator>
		
		<category><![CDATA[Advanced Techniques]]></category>

		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[Navigation]]></category>

		<category><![CDATA[functions]]></category>

		<category><![CDATA[jquery]]></category>

		<category><![CDATA[js]]></category>

		<guid isPermaLink="false">http://www.cssnewbie.com/?p=424</guid>
		<description><![CDATA[I'm all about efficiency when I'm writing web code, and navigation is often one of those areas where I try to improve my efficiency. Here are some ways to automatically style your "active" navigation elements using some streamlined JavaScript and/or jQuery.]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.cssnewbie.com/wp-content/uploads/2009/04/active-nav.png" alt="active navigation element" title="active navigation element" width="579" height="125" class="alignnone size-full wp-image-426" /></p>
<p>I&#8217;m all about efficiency when I&#8217;m writing web code. Any time I find myself writing the same functionality more than once or twice, I try to consider whether my repeated code could be wrapped into a function of some sort.</p>
<p>Navigation is often one of those areas where I try to improve my efficiency. I like my navigation elements to pull double duty. I want them to:</p>
<ol>
<li>Show the user <em>where they can go,</em> and</li>
<li>Show the user <em>where they currently are.</em></li>
</ol>
<p>In other words, I want some sort of visual indication in my navigation that shows my user which section of my site they&#8217;re in. You can see this on the CSS Newbie site: if you click on <a href="http://www.cssnewbie.com/toc/">the TOC (Table of Contents) link</a> in the bar at the top of the page, you&#8217;ll see that link gets special styling when the table of content loads.</p>
<p>Now, I could manually set this on every page using a CSS class. But that&#8217;s inefficient &mdash; depending on the size of my site, I could end up writing dozens or hundreds of lines of one-off code. And why go to all that work, when you could just wrap it all up into a nice JavaScript function?<span id="more-424"></span></p>
<p>First, I&#8217;ll explain the logic behind my functions &mdash; because they won&#8217;t work equally well for every site. Then I&#8217;ll walk you through a few examples of the code that makes it all happen.</p>
<h3>The Logic</h3</p>
<p>All of my functions assume a very clean, straightforward directory structure. For example, if you have an About section, a Blog section, and a Contact section on your site, a logical directory structure might be: </p>
<pre>/
/about/
/blog/
/contact/
</pre>
<p>And if you had several blog entries inside your blog directory, your structure might grow like this:</p>
<pre>/
/about/
/blog/
/blog/post-one/
/blog/post-two/
/blog/post-three/
/contact/
</pre>
<p>And therefore, a function could logically assume that anything inside the blog directory should be considered a part of the blog section of your site, and mark the blog link as active for those pages. This makes our job a lot easier. And luckily, most CMS platforms make this sort of directory structure pretty easy to create.</p>
<p>The functions also assume that you have either a fairly shallow directory structure, or that you&#8217;re not linking to too many similarly nested directories. What I mean by this is, if you have this sort of a structure:</p>
<pre>/
/contact/
/contact/me/
/contact/me/here/
</pre>
<p>And you wanted to link to both /contact/ and /contact/me/here/ in your navigation bar, you might run into problems distinguishing between the two. There are ways to increase precision, but they come at the cost of flexibility. </p>
<p>But enough of that. Let&#8217;s get to the good stuff!</p>
<h3>A JavaScript Solution</h3>
<p>I&#8217;ve written about this method before, when I previously talked about <a href="http://www.cssnewbie.com/intelligent-navigation/">building intelligent navigation bars.</a> This technique is nice because it doesn&#8217;t rely on any JS frameworks, so you can add it to older sites without needing jQuery or the like. The basic function looks like this:</p>
<pre class="js">function setActive() {
  aObj = document.getElementById('nav').getElementsByTagName('a');
  for(i=0;i&lt;aObj.length;i++) {
    if(document.location.href.indexOf(aObj[i].href)&gt;=0) {
      aObj[i].className='active';
    }
  }
}</pre>
<p>This function looks for an element with an id of &#8220;nav&#8221; (presumably your navigation bar), then looks at each of the anchor tags inside it. It then compares the anchor tag&#8217;s href tag with the page&#8217;s URL. If the href tag is contained within the URL anywhere, it gives that link a class of &#8220;active,&#8221; which I can then style specially in my CSS.</p>
<p>As an example of what I mean by all that, if I had an anchor tag in my navigation bar that linked to &#8220;/blog/&#8221; and the page I was on was &#8220;/blog/this-is-a-post.html&#8221;, my blog link would be styled as active, because &#8220;/blog/&#8221; is contained within &#8220;/blog/this-is-a-post.html&#8221;.</p>
<p>As a final note, you wouldn&#8217;t want to call this function until the page was finished loading: if you call it too soon, your links won&#8217;t exist yet! So you can either call it at the very end of your document, or dynamically call it when your page is done loading, with something like this:</p>
<pre class="js">window.onload = setActive;</pre>
<h3>A jQuery Solution</h3>
<p>If you are already loading a framework like jQuery (like I do on almost every site I work on these days), this sort of functionality could be written even more succinctly. And like I said earlier, I&#8217;m a sucker for efficiency. Here&#8217;s a jQuery solution that does essentially the same thing in a much smaller space:</p>
<pre class="js">$(document).ready(function() {
	$('#nav a[href^="/' + location.pathname.split("/")[1] + '"]').addClass('active');
});</pre>
<p>This function is making use of both native JavaScript and jQuery tricks to reach a whole new level of brevity. First, the whole thing is wrapped in a &#8220;document ready&#8221; function, which means it won&#8217;t fire until the page is loaded and our links are in place. Next, we&#8217;re looking for anchor tags inside our &#8220;nav&#8221; ID. And really, we&#8217;re looking for a very specific anchor tag: one whose href <strong>starts with</strong> (^=) a slash, followed by a part of our <strong>page&#8217;s location</strong> (location.pathname). Specifically, we&#8217;re looking for the first directory in our page&#8217;s URL.</p>
<p>We&#8217;re doing this by making use of the JavaScript split() method, which lets us take any string (for example, &#8220;/blog/this-is-a-post.html&#8221;) and break it into an array based on a substring (in our case, the forward slash). If you&#8217;re familiar with PHP, it&#8217;s similar to the explode() function. In our example, we&#8217;d end up with a three-part array that looked like this: </p>
<pre>["","blog","this-is-a-post.html"]</pre>
<p>Which means that if we look at the second value of our array (arrays start counting at zero, so [1] is the second value), that should give our first-level directory (&#8221;blog&#8221;, in our example). This lets us match any subsequent child directories with our parent in the navigation bar.</p>
<h3>Tweaking for Home Links</h3>
<p>Our jQuery function works great in most scenarios, but it fails if you have a &#8220;home&#8221; link where you&#8217;re just pointing to the root directory, like this:</p>
<pre class="html">&lt;a href=&quot;/&quot;&gt;Home&lt;/a&gt;</pre>
<p>And because I tend to have a link like that, I needed a workaround. Here&#8217;s a way to get around that with just a little more code to account for our special case:</p>
<pre class="js">$(document).ready(function() {
	if(location.pathname != "/") {
		$('#nav a[href^="/' + location.pathname.split("/")[1] + '"]').addClass('active');
	} else $('#nav a:eq(0)').addClass('active');
});</pre>
<p>Here, we&#8217;re checking to see if we&#8217;re in the root directory. If so, we&#8217;re skipping the loop through our anchor tags and just making a specific anchor tag active. In this case, I&#8217;m giving the active class to the first anchor in our list (which is the most common location for a home link).</p>
<p>And that&#8217;s that. If you know of even more efficient or fool-proof ways to accomplish this task, I&#8217;d love to hear about them in the comments section. Or if you&#8217;re skilled in a framework other than jQuery, feel free to share the equivalent code!</p>
<p>Note: I apologize for the long gap between articles. I had some problems while rebuilding my PC (DOA motherboard) and was without my computer for several weeks.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/cssnewbie?a=WFmpM51NipQ:LKWSYBv7T30:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/cssnewbie?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/cssnewbie?a=WFmpM51NipQ:LKWSYBv7T30:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/cssnewbie?i=WFmpM51NipQ:LKWSYBv7T30:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/cssnewbie?a=WFmpM51NipQ:LKWSYBv7T30:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/cssnewbie?i=WFmpM51NipQ:LKWSYBv7T30:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/cssnewbie?a=WFmpM51NipQ:LKWSYBv7T30:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/cssnewbie?i=WFmpM51NipQ:LKWSYBv7T30:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/cssnewbie?a=WFmpM51NipQ:LKWSYBv7T30:l6gmwiTKsz0"><img src="http://feeds.feedburner.com/~ff/cssnewbie?d=l6gmwiTKsz0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/cssnewbie?a=WFmpM51NipQ:LKWSYBv7T30:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/cssnewbie?i=WFmpM51NipQ:LKWSYBv7T30:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/cssnewbie/~4/WFmpM51NipQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.cssnewbie.com/using-javascript-to-style-active-navigation-elements/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.cssnewbie.com/using-javascript-to-style-active-navigation-elements/</feedburner:origLink></item>
		<item>
		<title>Reader Response: A Simple, Streamlined E-Commerce Solution</title>
		<link>http://feedproxy.google.com/~r/cssnewbie/~3/ZqlyRG_DpEY/</link>
		<comments>http://www.cssnewbie.com/a-simple-streamlined-e-commerce-solution/#comments</comments>
		<pubDate>Wed, 08 Apr 2009 16:01:48 +0000</pubDate>
		<dc:creator>Rob Glazebrook</dc:creator>
		
		<category><![CDATA[Ecommerce]]></category>

		<category><![CDATA[Polls]]></category>

		<category><![CDATA[Resources]]></category>

		<category><![CDATA[foxycart]]></category>

		<category><![CDATA[payflow]]></category>

		<category><![CDATA[paypal]]></category>

		<category><![CDATA[poll]]></category>

		<category><![CDATA[shopping cart]]></category>

		<category><![CDATA[template]]></category>

		<guid isPermaLink="false">http://www.cssnewbie.com/?p=418</guid>
		<description><![CDATA[Today I come to you with my arms wide open &#8212; and my shoulders caught somewhere between a slump and a shrug. I've been tearing my hair out over the last couple of months looking for the perfect ecommerce solution. I've come up short.]]></description>
			<content:encoded><![CDATA[<p>Today, dear readers, I come to you with my arms wide open &mdash; and my shoulders caught somewhere between a slump and a shrug. I&#8217;ve been tearing my hair out over the last couple of months looking for the perfect ecommerce solution for my specific needs and wants. I&#8217;ve come up short.</p>
<p>But it occurs to me that I have a lot of smart, savvy readers here on CSS Newbie &mdash; and maybe, just maybe, you&#8217;ll be able to help me find the perfect shopping cart. Below, I&#8217;ll explain specifically what I&#8217;m looking for (and a bit about what I&#8217;m <em>not</em> looking for, too). If you know of a cart that meets my needs &mdash; or even just some of them &mdash; <strong>please</strong> do not hesitate to let me know! I&#8217;m hoping that the comments on this article will prove as plentiful as Starbucks on the open prairie. And twice as useful.<span id="more-418"></span></p>
<h3>I Want a Simple, User-Friendly Cart that Stays Out of My Way.</h3>
<p>That about sums it up, really. But for more detail, here&#8217;s what I want/need in a cart:</p>
<ul>
<li><strong>A self-hosted solution.</strong> If it weren&#8217;t for this requirement, I think<a href="http://www.foxycart.com/"> Foxycart would be my #1 contender.</a> Consider that a hint &mdash; if you know of something Foxycart-eque, but is self-hosted instead, <em>please</em> let me know!</li>
<li><strong>Supports everything <a href="https://www.paypal.com/">PayPal</a> has to offer.</strong> Specifically, I want something that can support <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_wp-pro-overview-outside&#038;nav=2.0.1">Website Payments Pro</a> and the <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_payflow-pro-overview-outside">Payflow Pro</a> gateway. This way I can handle payments on my site, but still take advantage of PayPal&#8217;s expertise, PCI compliance, and competitive pricing.</li>
<li><strong>Flexible, <em>straightforward</em> templating.</strong> I am a front-end developer. Any cart solution that tries to stand between me and my code or that makes templating a holy hell isn&#8217;t a good solution. I want simple, straightforward flexibility. For example, I&#8217;ve been working with <a href="http://www.magentocommerce.com/">Magento</a> a lot recently, and while it has a lot of great features, it&#8217;s a <strong>huge</strong> pain to deviate too far from the standard build. Every small change requires updates in multiple disparate files and hours of time for a five-minute job. My ideal solution would let me build my pages however I wanted, and just drop in the &#8220;cart&#8221; functionality wherever I cared to do so.</li>
<li><strong>Good support of downloadable products.</strong> The stores I&#8217;m building will have both hard and soft goods, so I need the cart to work equally smoothly with both.</li>
<li><strong>Built for <a href="http://en.wikipedia.org/wiki/LAMP_(software_bundle)">LAMP</a> servers.</strong> The ideal solution would run on PHP/MySQL, but I would consider other LAMP-friendly options. Sorry, but ASP/.NET solutions aren&#8217;t a possibility for me.</li>
<li><strong>A single product database.</strong> This solution will be running multiple stores, but several of the stores will share some products. In the interest of avoiding redundant data, I&#8217;d like to have a single product database that all my stores can draw from.</li>
<li><strong>Access to the source.</strong> I don&#8217;t want to have to wait for a team halfway around the world or a community of volunteer developers to get around to building the functionality I need if I think I could tackle the project myself. If I can&#8217;t have access to the source itself, an exceptional plugin system would be a good alternative.</li>
<li><strong>A flexible discounting system.</strong> I want to be able to offer (as a fake example) 20% off orders of $50 or more on certain products. I want to discount items if people buy two or more of the same product. I want sales that run for three weeks, and expire automatically. Or at least some of those things.</li>
</ul>
<p>That&#8217;s the basics of what I need, folks. That isn&#8217;t too much to ask, is it?</p>
<p>To summarize, <strong>I&#8217;m looking for a simple, straightforward shopping cart that makes templating a breeze, runs on PHP/MySQL, supports PayPal gateways, allows virtual goods and discounts, and is something I can install locally and modify.</strong> I do not need a solution that tries to be everything at once &mdash; it doesn&#8217;t have to contain a CMS, a catalog, or an inventory system. It doesn&#8217;t have to provide a newsletter, it needn&#8217;t compare items, and it shouldn&#8217;t try to walk my dog on Thursdays. I don&#8217;t want a jack-of-all-trades: I want a master of one (or two).</p>
<p>I also want to clarify: <strong>this does not have to be a free solution.</strong> If you know of a commercial option that does all this, I would be <em>very</em> excited to hear about it.</p>
<p>So! Let me know what you know in the comments below. Even if you know of a cart that fulfills <em>some</em> of these needs, I would be excited to hear about it &mdash; there&#8217;s always the chance I can customize it to do what I need from there.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/cssnewbie?a=ZqlyRG_DpEY:rSjOiz3y6Oo:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/cssnewbie?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/cssnewbie?a=ZqlyRG_DpEY:rSjOiz3y6Oo:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/cssnewbie?i=ZqlyRG_DpEY:rSjOiz3y6Oo:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/cssnewbie?a=ZqlyRG_DpEY:rSjOiz3y6Oo:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/cssnewbie?i=ZqlyRG_DpEY:rSjOiz3y6Oo:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/cssnewbie?a=ZqlyRG_DpEY:rSjOiz3y6Oo:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/cssnewbie?i=ZqlyRG_DpEY:rSjOiz3y6Oo:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/cssnewbie?a=ZqlyRG_DpEY:rSjOiz3y6Oo:l6gmwiTKsz0"><img src="http://feeds.feedburner.com/~ff/cssnewbie?d=l6gmwiTKsz0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/cssnewbie?a=ZqlyRG_DpEY:rSjOiz3y6Oo:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/cssnewbie?i=ZqlyRG_DpEY:rSjOiz3y6Oo:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/cssnewbie/~4/ZqlyRG_DpEY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.cssnewbie.com/a-simple-streamlined-e-commerce-solution/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.cssnewbie.com/a-simple-streamlined-e-commerce-solution/</feedburner:origLink></item>
		<item>
		<title>A Simple jQuery Stylesheet Switcher</title>
		<link>http://feedproxy.google.com/~r/cssnewbie/~3/ZWTG4BKw32Y/</link>
		<comments>http://www.cssnewbie.com/simple-jquery-stylesheet-switcher/#comments</comments>
		<pubDate>Fri, 03 Apr 2009 01:48:36 +0000</pubDate>
		<dc:creator>Rob Glazebrook</dc:creator>
		
		<category><![CDATA[Basic Techniques]]></category>

		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[Quick Tip]]></category>

		<category><![CDATA[css]]></category>

		<category><![CDATA[jquery]]></category>

		<category><![CDATA[stylehseet]]></category>

		<category><![CDATA[swap]]></category>

		<category><![CDATA[switch]]></category>

		<guid isPermaLink="false">http://www.cssnewbie.com/?p=410</guid>
		<description><![CDATA[There are lots of reasons you might want to offer your users more than one CSS file for your website. But whatever the reason, it's amazingly easy to create a function that swaps between multiple stylesheets using a few lines of jQuery.]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.cssnewbie.com/example/stylesheet-switcher/"><img src="http://www.cssnewbie.com/wp-content/uploads/2009/04/stylesheeet-switcher.gif" alt="jQuery stylesheeet switcher" title="jQuery stylesheeet switcher" width="579" height="150" class="alignnone size-full wp-image-412" /></a></p>
<p>There are lots of reasons you might want to offer your users more than one CSS file for your website:</p>
<ul>
<li>You want to offer a &#8220;stylish&#8221; low-contrast and an easy-to-read high-contrast version of your site.</li>
<li>You have many low-vision readers and want to give them easy access to a customized stylesheet with a larger typeface.</li>
<li>Your site is schizophrenic and you want to be able to change the look quickly.</li>
</ul>
<p>Whatever the reason, it&#8217;s amazingly easy to create a function that swaps between multiple stylesheets using jQuery.</p>
<p>The first step of course is to build several different CSS files, which we&#8217;ll then swap between. Once that is done, we can dive into the XHTML and jQuery that makes the magic happen.<span id="more-410"></span></p>
<h3>The XHTML</h3>
<p>First, we need to create a set of links that will allow the user to swap between CSS files. You can make this as simple or as fancy as you&#8217;d like. For the sake of brevity, my links are simple:</p>
<pre class="html">&lt;ul id=&quot;nav&quot;&gt;
	&lt;li&gt;&lt;a href=&quot;#&quot; rel=&quot;/path/to/style1.css&quot;&gt;Default CSS&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href=&quot;#&quot; rel=&quot;/path/to/style2.css&quot;&gt;Larger Text&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href=&quot;#&quot; rel=&quot;/path/to/style3.css&quot;&gt;Something Different&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</pre>
<p>Here I have three links, each with a &#8220;rel&#8221; attribute indicating which CSS file the link will load. Technically, I could have just as easily put this information in the &#8220;href&#8221; attribute, but I didn&#8217;t want to for one specific reason: if the user has JavaScript disabled and the CSS file is listed in the href, then clicking the link will send the user to the CSS file directly (not loading it like we intended). But our way, if JS is disabled, the user gets nothing at all: which is certainly preferable to the less savory alternative.</p>
<h3>The jQuery</h3>
<p>Like I promised, the jQuery is really simple:</p>
<pre class="js">$(document).ready(function() {
	$("#nav li a").click(function() {
		$("link").attr("href",$(this).attr('rel'));
		return false;
	});
});</pre>
<p>This function waits until the document is loaded (generally an important step when interacting with the DOM), then attaches a click function to each of our nav anchors. The function basically says, &#8220;when someone clicks on this link, replace the link (stylesheet) tag&#8217;s href attribute with the contents of this link&#8217;s rel attribute.&#8221;  The &#8220;return false&#8221; at the end just stops the browser from trying to follow the link.</p>
<p>Of course, you might have to get more detailed if you have more than one link tag, for example, but that&#8217;s easily done by giving the link tag a class (&#8221;changeme,&#8221; for argument&#8217;s sake), and writing something like this:</p>
<pre class="js">$("link.changeme").attr("href",$(this).attr('rel'));</pre>
<p>And while this stylesheet switcher is already complete, we might want to give it some memory: after all, your users might get annoyed if they have to switch their styles back to their preferences every time they visit your site. For that, we&#8217;ll need to set a cookie. And to make that easier, I&#8217;ll use <a href="http://plugins.jquery.com/project/Cookie">the jQuery cookie plugin</a> (which <a href="http://www.cssnewbie.com/jquery-popout-ad-part-3/">I&#8217;ve talked about previously when building a popout ad</a>).</p>
<p>With the plugin loaded, we can modify our jQuery thusly:</p>
<pre class="js">$(document).ready(function() {
	if($.cookie("css")) {
		$("link").attr("href",$.cookie("css"));
	}
	$("#nav li a").click(function() {
		$("link").attr("href",$(this).attr('rel'));
		$.cookie("css",$(this).attr('rel'), {expires: 365, path: '/'});
		return false;
	});
});</pre>
<p>Now we have two statements. The first one checks as soon as the page is done loading to see if a cookie called &#8220;css&#8221; has been set. If so, it sets the stylesheet to be the one indicated in that cookie. Otherwise, it does nothing.</p>
<p>Our click function is much the same, except after we set the stylesheet, we also set a cookie. This cookie doesn&#8217;t expire for an entire year (and each time the user changes their stylesheet preferences, it would reset this timer), giving them a good 365 of CSS bliss.</p>
<h3>Fine Tuning</h3>
<p>There is one minor annoyance with this stylesheet switcher: there&#8217;s generally a flash of the &#8220;default&#8221; CSS when the user loads the page. That&#8217;s because the script waits until the document is &#8220;ready&#8221; before switching the link&#8217;s href. There is a way around this: moving the first &#8220;if&#8221; statement outside of the document ready function, like so:</p>
<pre class="js">if($.cookie("css")) {
	$("link").attr("href",$.cookie("css"));
}
$(document).ready(function() {
	$("#nav li a").click(function() {
		$("link").attr("href",$(this).attr('rel'));
		$.cookie("css",$(this).attr('rel'), {expires: 365, path: '/'});
		return false;
	});
});</pre>
<p>Generally speaking, you don&#8217;t want to run any jQuery until your document is ready. However, so long as your jQuery comes <em>after your link tag</em> in your document structure, like shown below, this shouldn&#8217;t be a major concern:</p>
<pre class="html">&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;style1.css&quot; /&gt;
&lt;script type=&quot;text/javascript&quot; language=&quot;javascript&quot; src=&quot;jquery.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; language=&quot;javascript&quot; src=&quot;jquery.cookie.js&quot;&gt;&lt;/script&gt;
&lt;script&gt;... your jQuery goes here...&lt;/script&gt;</pre>
<p>This means your jQuery will run before the document is done loading, and thus your link tag&#8217;s href will be swapped before your CSS has been applied. As I said before, it&#8217;s generally a bad idea to manipulate the DOM before document ready, but because we know the exact tag we want to manipulate and can place our jQuery below it in the DOM, we should be safe in this one specific instance.</p>
<p><a href="http://www.cssnewbie.com/example/stylesheet-switcher/">Here&#8217;s an example if you would like to see this technique in action.</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/cssnewbie?a=ZWTG4BKw32Y:I1a58WSN6qo:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/cssnewbie?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/cssnewbie?a=ZWTG4BKw32Y:I1a58WSN6qo:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/cssnewbie?i=ZWTG4BKw32Y:I1a58WSN6qo:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/cssnewbie?a=ZWTG4BKw32Y:I1a58WSN6qo:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/cssnewbie?i=ZWTG4BKw32Y:I1a58WSN6qo:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/cssnewbie?a=ZWTG4BKw32Y:I1a58WSN6qo:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/cssnewbie?i=ZWTG4BKw32Y:I1a58WSN6qo:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/cssnewbie?a=ZWTG4BKw32Y:I1a58WSN6qo:l6gmwiTKsz0"><img src="http://feeds.feedburner.com/~ff/cssnewbie?d=l6gmwiTKsz0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/cssnewbie?a=ZWTG4BKw32Y:I1a58WSN6qo:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/cssnewbie?i=ZWTG4BKw32Y:I1a58WSN6qo:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/cssnewbie/~4/ZWTG4BKw32Y" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.cssnewbie.com/simple-jquery-stylesheet-switcher/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.cssnewbie.com/simple-jquery-stylesheet-switcher/</feedburner:origLink></item>
		<item>
		<title>15 Surefire Ways to Break Your CSS</title>
		<link>http://feedproxy.google.com/~r/cssnewbie/~3/ib8CLW9iaO8/</link>
		<comments>http://www.cssnewbie.com/15-surefire-ways-to-break-your-css/#comments</comments>
		<pubDate>Thu, 26 Mar 2009 19:28:23 +0000</pubDate>
		<dc:creator>Rob Glazebrook</dc:creator>
		
		<category><![CDATA[Basic Techniques]]></category>

		<category><![CDATA[Bugs and Fixes]]></category>

		<category><![CDATA[IDs and Classes]]></category>

		<category><![CDATA[Organization]]></category>

		<category><![CDATA[bugs]]></category>

		<category><![CDATA[errors]]></category>

		<category><![CDATA[properties]]></category>

		<category><![CDATA[rules of css]]></category>

		<guid isPermaLink="false">http://www.cssnewbie.com/?p=403</guid>
		<description><![CDATA[When your CSS doesn't behave the way it should, web design can be downright tedious. But some of the the biggest CSS blunders stem from the simplest of errors. Knowing what some of those errors are and remembering to look for them can save you hours of wasted labor.]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.flickr.com/photos/ultimateslug/109566859/"><img src="http://www.cssnewbie.com/wp-content/uploads/2009/03/broken-monitor.jpg" alt="&#039;Fixed&#039; by Don Fulano. Used under a Creative Commons license." title="&#039;Fixed&#039; by Don Fulano. Used under a Creative Commons license." width="579" height="250" class="alignnone size-full wp-image-404" /></a></p>
<p>The life of a CSS developer isn&#8217;t all about attending glamorous champagne parties, jet-setting around the world and hanging out with supermodels. In fact, when your CSS doesn&#8217;t behave the way it should, the job can be downright tedious. I&#8217;ve spent untold hours of my life debugging my code &mdash; and I&#8217;m guessing I&#8217;m not alone here.</p>
<p>But as silly as it may seem, some of the biggest CSS blunders stem from the simplest of errors. Knowing what some of those errors are and remembering to look for them can save you hours of wasted labor. Here are fifteen ways I&#8217;ve found to break my CSS for sure &mdash; and fifteen things I always look for whenever I have a problem in my code.<span id="more-403"></span></p>
<h3>Missing a Semicolon</h3>
<p>CSS rules are comprised of property-value pairs (declarations) followed by a semicolon. Accordng to the CSS specification, the last declaration doesn&#8217;t need a semicolon &mdash; because the closing brace effectively ends the declaration just as well. That means something like this is perfectly acceptable: </p>
<pre class="css">body {
	background-color: #444;
	color: #eee }</pre>
<p>The only problem is, as soon as you decide to add another declaration to your previous rule, you&#8217;ve now made it all too easy to forget to add the semicolon to your once-last rule:</p>
<pre class="css">body {
	background-color: #444;
	color: #eee
font-family: Helvetica, Arial, sans-serif }</pre>
<p>The result? Your font-family rule never gets applied, because the parser reads &#8220;font-family&#8221; as part of the color value. Which is why I make a habit of adding the final semicolon in a rule, no matter what.</p>
<h3>Missing a Colon</h3>
<p>I&#8217;ve seen this particular problem crop up frequently while teaching classes on CSS. People get excited when CSS starts to make sense, and their typing speed increases. The downside: this makes errors of omission much more likely. And a missing colon is particularly tough to see, since it sits right in the middle of a declaration. Consider the following two lines:</p>
<pre class="css">body { font-family Helvetica, Arial, sans-serif; }
body { font-family: Helvetica, Arial, sans-serif; }</pre>
<p>It&#8217;s easy to see how the colon could get overlooked in the jumble of braces, hyphens, semicolons and cryptic words. As a rule of thumb, if you only have one declaration not behaving itself, this is a good place to start looking.</p>
<h3>Missing a Brace</h3>
<p>{Braces} around a CSS rule are like the circle of life: regular, natural, and expected. And if you ever miss a brace (generally a closing brace for whatever reason) &#8212; just like if you have a zombified corpse that refuses to die &#8212; you suddenly have all sorts of mayhem on your hands.</p>
<p>When an unsuspecting browser comes across a pair of rules like this:</p>
<pre class="css">body {
	font-family: Helvetica, Arial, sans-serif;
#wrap {
	width: 960px; }</pre>
<p>The browser is going to choke. Two opening braces before a closing brace is right out: everything from your #wrap rule (in this example) on would be ignored. </p>
<p>However, this does make debugging easier. Do you have a whole chunk of CSS being ignored? Which is the first rule that is being neglected? There&#8217;s a good chance you have an uneven number of braces hanging out in the vicinity.</p>
<h3>Misspelled Properties</h3>
<p>I consider the following few errors the bane of dyslexic developers everywhere. Generally speaking, I&#8217;m a good speller. But when I&#8217;m &#8220;in the zone&#8221; and typing as fast as my fingers can carry me, I tend to transpose a few letters here and there. In writing, this isn&#8217;t such a big deal: people can generally figure out what I mean. Computers, sadly, are less discerning. </p>
<pre class="css">div { border-bototm: 5px; }</pre>
<p>Now, I have no idea what a &#8220;bototm&#8221; is, but I do know I write the word at least one time in five when I&#8217;m trying to refer to the lower edge of an element. I&#8217;m lucky in that I have a decent eye for editing and often catch these mistakes as I make them. If you&#8217;re not so fortunate, using a program with code coloring like <a href="http://notepad-plus.sourceforge.net">Notepad++</a> or <a href="http://www.amazon.com/gp/product/B001EUDIZE?ie=UTF8&#038;tag=cssnewbie-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=B001EUDIZE">Adobe Dreamweaver (my personal favorite)</a> can make the job a lot easier: if a property isn&#8217;t colored like the other properties, than it&#8217;s probably not much of a property at all.</p>
<h3>Misspelled Values</h3>
<p>Misspellings aren&#8217;t limited to just properties. And sometimes a misspelled value can be even more difficult to notice:</p>
<pre class="css">#wrap { padding: 10px 20pz 25px 20px; }</pre>
<p>Unfortunately for the rule above, I&#8217;m fairly sure only Snoop Dogg and I have ever tried to measure elements in pizzles. Instead of the generous padding you&#8217;d expect this rule to generate, this one misspelled unit renders the entire declaration invalid.</p>
<h3>Misspelled Classes and IDs</h3>
<p>No matter how often I create a div with an ID of &#8220;navigation,&#8221; I still find myself writing rules that look more like this:</p>
<pre class="css">#navigaiton { float: left; } </pre>
<p>This can be a frustrating error to track down, because color-coded editors won&#8217;t help you out here: you could just as easily purposefully name an element &#8220;navigaiton&#8221; if you really wanted. But I&#8217;d recommend against it.</p>
<h3>Improperly Ordered Values</h3>
<p>Some CSS properties have a built-in shorthand, which is a great way to save yourself a few lines of code. Unfortunately, most of the shorthand properties are very picky about the order of the property&#8217;s values. For example:</p>
<pre class="css">div { font: 2em Helvetica, Arial, sans-serif; }
a { font: "Times New Roman", serif 1.5em; }</pre>
<p>The first rule will result in all divs gaining a specific typeface and size. The second rule will result in a debugging session &mdash; while it&#8217;s okay to leave some values out of the font declaration, changing up the order of the values will result in problems.</p>
<h3>Measurement Values Without Units</h3>
<p>CSS Newbie reader Justin reminded me of this problem <a href="http://www.cssnewbie.com/five-quick-css-fixes/">the last time I wrote about CSS faux pas.</a> With only a few limited exceptions, all measurement values in CSS need a unit of measurement associated with it. Take the following rule for example:</p>
<pre class="css">#wrap { margin: 3; }</pre>
<p>Three <em>what</em>? Ems? Inches? Pizzles? The flexibility of CSS that allows us to pick from several units of measurement also means specifying a unit is fairly important.</p>
<h4>Bonus &mdash; Two unit-agnostic measurements:</h4>
<ol>
<li>Values of zero don&#8217;t need a unit of measurement. Turns out, zero pixels and zero miles are <em>exactly the same length.</em></li>
<li>Line heights needn&#8217;t have a specific unit. A line height of &#8220;1.5&#8243;, for example, will simply assume you meant &#8220;1.5 times my font size.&#8221; For more on this phenomenon, <a href="http://meyerweb.com/eric/thoughts/2006/02/08/unitless-line-heights/">visit Eric Meyer&#8217;s article on Unitless Line Heights.</a></li>
</ol>
<h3>Competing Identical Rules</h3>
<p>Once a stylesheet gets to be a certain length, it can be difficult to remember which rules you&#8217;ve already written <a href="http://www.cssnewbie.com/organized-style-sheet/">unless your CSS is very well organized.</a> And two identical rules at different spots in your CSS file can wreak havoc on your design and sanity alike.</p>
<pre class="css">ul li { margin: 0 2em; }
... 300 lines later ...
ul li { margin: 0; padding: 10px; }</pre>
<p>In this scenario, the latter rule would win out over the former, thus removing the margin and applying padding instead. But if you&#8217;ve forgotten about this duplicity, you might go back into your CSS later and try editing the <em>first</em> rule only, and remain perplexed as to why, no matter how you tweak your margin, you can&#8217;t seem to make any difference.</p>
<h3>Unintentionally Competing Rules</h3>
<p>A similar problem could force your CSS to compete with itself in ways you didn&#8217;t expect. For example, if you had the following code in your XHTML:</p>
<pre class="html">&lt;div id="navigation" class="nav"&gt;...&lt;/div&gt;</pre>
<p>You could refer to this element by either its class or its ID. The problem arises when you do both, and forget that you&#8217;ve done so:</p>
<pre class="css">.nav { width: 50%; }
... later in the code ...
#navigation { width: 500px; }</pre>
<p>This code would result in a fixed-width navigation bar, even though the first rule would suggest a more flexible width. Again, <a href="http://www.cssnewbie.com/organized-style-sheet/">having a well organized stylesheet</a> is the easiest way to avoid this problem.</p>
<h3>Calling a Class an ID (or vice-versa)</h3>
<p>I fall into this particular trap all the time. I&#8217;ll write a rule like this: </p>
<pre class="css">.navigation {
	float: left;
	width: 100%;
	height: 4em; }</pre>
<p>And nothing will happen! It often takes me a minute or two to realize that the real problem is that I&#8217;d given my navigation bar an ID, not a class. My best advice here is to pick a naming system that works well for you and <strong>be consistent.</strong> If you always call your top navigation bar &#8220;#topnav&#8221;, for example, you&#8217;re far less likely to misremember your element names.</p>
<h3>Using a Nonexistent Property</h3>
<p>Not all CSS properties are named the most intuitively. For example, this might look like a perfectly acceptable rule to someone new to CSS:</p>
<pre class="css">body { text-size: 3em; }</pre>
<p>The problem is, while there are certainly several text-riffic properties, text-size isn&#8217;t one of them. Instead, we use font-size. Which means that the rule above wouldn&#8217;t do much of anything. <a href="http://www.amazon.com/gp/product/B001EUDIZE?ie=UTF8&#038;tag=cssnewbie-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=B001EUDIZE">Intelligent code-coloring editors like Dreamweaver</a> usually make this sort of debugging much easier: if it&#8217;s not a real CSS property, it won&#8217;t be the same color as the surrounding properties. That&#8217;s usually my first clue I&#8217;ve done something wrong.</p>
<h3>Using a Nonexistent Value</h3>
<p>This is a sister stumbling block to the one above. Some values just seem to make sense, but will fail you nonetheless:</p>
<pre class="css">td { vertical-align: center; }</pre>
<p>You would assume that this rule would vertically center your table text, right? Unfortunately, while &#8220;center&#8221; is indeed an acceptable value for text-align, vertical-align uses the perhaps less intuitive &#8220;middle&#8221; instead. And you&#8217;d have to ask a better educated rhetorician than me to figure out the difference between middle and center in this context, because I&#8217;m at a loss.</p>
<h3>Improperly Matching Properties and Values</h3>
<p>Certain CSS declarations can look correct even to the trained eye, unless that eye is paying particularly close attention. For example:</p>
<pre class="css">a { text-transform: italic; }</pre>
<p>While this might look like a perfectly reasonable rule, you won&#8217;t end up with italicized text. That&#8217;s because &#8220;italic&#8221; belongs to the font-style property, not the text-transform property. But even most advanced editors won&#8217;t catch that bug, as you&#8217;ve used a perfectly reasonable property and value &mdash; you&#8217;ve just used them in an inappropriate combination.</p>
<h3>Not Closing Comments</h3>
<p>The <a href="http://blogthememachine.com/">gentle persons at BlogThemeMachine</a> tipped me off to this common CSS problem. Can you spot the major difference between these two sets of rules?</p>
<pre class="css">/* Navigation goes here. */
#nav {
	float: left;
	width: 100%;
	height: 3em; }</pre>
<pre class="css">/* Navigation goes here. /*
#nav {
	float: left;
	width: 100%;
	height: 3em; }</pre>
<p>The only difference is that the second rule has an improperly closed comment tag: /* versus */. That seemingly insignificant difference can result in entire swaths of your CSS suddenly not working. In fact, this tiny blunder will negate all your CSS from the start of your comment until you successfully close a <em>second</em> comment. Which if you&#8217;re using comments to organize your CSS means an entire section of your site will lose its styling.</p>
<p>These fifteen tiny blunders are sure to give you hours upon hours of CSS frustration&#8230; unless you know to watch for them. What are some other self-introduced bugs you often find in your code? I&#8217;d love to hear about them in the comments!</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/cssnewbie?a=ib8CLW9iaO8:lXo3OCxcFq0:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/cssnewbie?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/cssnewbie?a=ib8CLW9iaO8:lXo3OCxcFq0:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/cssnewbie?i=ib8CLW9iaO8:lXo3OCxcFq0:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/cssnewbie?a=ib8CLW9iaO8:lXo3OCxcFq0:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/cssnewbie?i=ib8CLW9iaO8:lXo3OCxcFq0:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/cssnewbie?a=ib8CLW9iaO8:lXo3OCxcFq0:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/cssnewbie?i=ib8CLW9iaO8:lXo3OCxcFq0:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/cssnewbie?a=ib8CLW9iaO8:lXo3OCxcFq0:l6gmwiTKsz0"><img src="http://feeds.feedburner.com/~ff/cssnewbie?d=l6gmwiTKsz0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/cssnewbie?a=ib8CLW9iaO8:lXo3OCxcFq0:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/cssnewbie?i=ib8CLW9iaO8:lXo3OCxcFq0:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/cssnewbie/~4/ib8CLW9iaO8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.cssnewbie.com/15-surefire-ways-to-break-your-css/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.cssnewbie.com/15-surefire-ways-to-break-your-css/</feedburner:origLink></item>
		<item>
		<title>New Poll: How Much CSS Do You Already Know?</title>
		<link>http://feedproxy.google.com/~r/cssnewbie/~3/jGl_bkFCdNA/</link>
		<comments>http://www.cssnewbie.com/new-poll-how-much-css-do-you-already-know/#comments</comments>
		<pubDate>Tue, 17 Mar 2009 14:21:05 +0000</pubDate>
		<dc:creator>Rob Glazebrook</dc:creator>
		
		<category><![CDATA[Polls]]></category>

		<category><![CDATA[Site News]]></category>

		<category><![CDATA[articles]]></category>

		<category><![CDATA[newbie]]></category>

		<category><![CDATA[poll]]></category>

		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://www.cssnewbie.com/?p=397</guid>
		<description><![CDATA[I've posted a new poll in the footer of the website, and I'd appreciate if you'd take a second or two and answer the question: how much CSS do you already know? This is a chance for me to get to know you a little bit better. It will also help me to produce the sort of content that you would find most useful.]]></description>
			<content:encoded><![CDATA[<p>Hey everyone, I&#8217;ve posted a new poll in the footer of the website, and I&#8217;d appreciate if you&#8217;d take a second or two (literally) and answer the question du jour: how much CSS do you already know?</p>
<p>This is a chance for me to get to know you, my audience, a little bit better. It will also help me do my darnedest to produce the sort of content that you would find most useful. So! Are you a true CSS newbie, already a big deal in the CSS world, or somewhere in between? Let me know in the poll below!</p>
<p>Note: There is a poll embedded within this post, please visit the site to participate in this post's poll.<span id="more-397"></span></p>
<p>Also, here are the results from the last poll, which asked, &#8220;what do you want to see on CSS Newbie in 2009?&#8221;:</p>
<ul>
<li><strong>59%</strong> of the voters wanted <strong>more long, tutorial-style articles</strong>.</li>
<li><strong>43.4%</strong> wanted <strong>more short, quick tip articles.</strong></li>
<li><strong>33.7%</strong> requested <strong>more entry-level, CSS-specific articles</strong>.</li>
<li><strong>31.3%</strong> wanted <strong>more advanced and non-CSS articles</strong>.</li>
<li><strong>24.1%</strong> wanted to see <strong>video tutorials and tips</strong>.</li>
<li><strong>19.3%</strong> were looking for <strong>a forum to help find solutions</strong>.</li>
<li><strong>12%</strong> wanted <strong>an email newsletter to stay in touch</strong>.</li>
</ul>
<p><em>(note: these add up to more than 100% because people could choose more than one option)</em></p>
<p>So obviously, the overwhelming answer is: more articles! Long, short, entry-level, and advanced&#8230; it seems there&#8217;s an audience for all four. And since I try to offer a combination of all four currently, that is a very encouraging result to see. And the other three &#8212; video tutorials, forums, and an email newsletter &#8212; were all desired by more than 10% of the respondents. Obviously I have a lot of planning to do!</p>
<p>So thanks everyone for participating in the last poll, and please take a second to give me your responses on this one!</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/cssnewbie?a=jGl_bkFCdNA:dolRC0KFVk4:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/cssnewbie?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/cssnewbie?a=jGl_bkFCdNA:dolRC0KFVk4:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/cssnewbie?i=jGl_bkFCdNA:dolRC0KFVk4:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/cssnewbie?a=jGl_bkFCdNA:dolRC0KFVk4:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/cssnewbie?i=jGl_bkFCdNA:dolRC0KFVk4:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/cssnewbie?a=jGl_bkFCdNA:dolRC0KFVk4:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/cssnewbie?i=jGl_bkFCdNA:dolRC0KFVk4:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/cssnewbie?a=jGl_bkFCdNA:dolRC0KFVk4:l6gmwiTKsz0"><img src="http://feeds.feedburner.com/~ff/cssnewbie?d=l6gmwiTKsz0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/cssnewbie?a=jGl_bkFCdNA:dolRC0KFVk4:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/cssnewbie?i=jGl_bkFCdNA:dolRC0KFVk4:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/cssnewbie/~4/jGl_bkFCdNA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.cssnewbie.com/new-poll-how-much-css-do-you-already-know/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.cssnewbie.com/new-poll-how-much-css-do-you-already-know/</feedburner:origLink></item>
		<item>
		<title>Build Custom Frameworks Easily with CSS Classes</title>
		<link>http://feedproxy.google.com/~r/cssnewbie/~3/tnYaQWMZqgo/</link>
		<comments>http://www.cssnewbie.com/build-custom-frameworks/#comments</comments>
		<pubDate>Tue, 10 Mar 2009 22:00:03 +0000</pubDate>
		<dc:creator>Rob Glazebrook</dc:creator>
		
		<category><![CDATA[Basic Techniques]]></category>

		<category><![CDATA[Frameworks and Libraries]]></category>

		<category><![CDATA[IDs and Classes]]></category>

		<category><![CDATA[Layout]]></category>

		<category><![CDATA[css]]></category>

		<category><![CDATA[custom]]></category>

		<category><![CDATA[framework]]></category>

		<category><![CDATA[xhtml]]></category>

		<guid isPermaLink="false">http://www.cssnewbie.com/?p=388</guid>
		<description><![CDATA[Generally speaking, I consider full-fledged CSS frameworks to be overkill. However, I still think that the foundation on which CSS frameworks are built &#8212; the concept of using classes to simplify layout and standardize design across similar elements &#8212; is very much worth investigation.]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.woodsmithshop.com/?from=cssnewbie"><img src="http://www.cssnewbie.com/wp-content/uploads/2009/03/column-wsshop.jpg" alt="Woodsmith Shop columns" title="Woodsmith Shop columns" width="579" height="200" class="alignnone size-full wp-image-389" /></a></p>
<p>Generally speaking, I consider full-fledged CSS frameworks to be overkill on all but the most absolutely complex projects or, on the other end of the spectrum, rapid proof-of-concept prototyping. Most people only use a few of the classes that any one CSS framework provides, but then still require their users to download the entire, and largely unused, stylesheet.</p>
<p>However, I still think that the foundation on which CSS frameworks are built &mdash; the concept of using classes to simplify layout and standardize design across similar elements &mdash; is very much worth investigation. But instead of relying on a one-size-fits-all (snuggie-esque?) solution, I&#8217;d encourage you to take a few minutes and build a custom, simplified framework that does exactly what you need it to do.<span id="more-388"></span></p>
<h3>The Back Story</h3>
<p>I recently built a website based on a fairly regular, consistent grid. The content area was 780px wide and would contain six &#8220;columns&#8221; of content with 12-pixel gutters between each of the columns, though various elements could span one or more of those columns. </p>
<p><img src="http://www.cssnewbie.com/wp-content/uploads/2009/03/column-examples.png" alt="sample content layouts in a six-column grid" title="sample content layouts in a six-column grid" width="579" height="200" class="alignnone size-full wp-image-390" /></p>
<p>Because of the general flexibility of the content combined with the rigidity of the columnar structure, my mind immediately jumped to frameworks as a way to get this design pushed out in a hurry. But in the end, I just couldn&#8217;t justify all that overhead, even to create a flexible six-column design. So instead, I decided to write my own mini-framework to do only what I needed.</p>
<h3>The Custom Framework</h3>
<p>Here&#8217;s the basic CSS I ended up writing:</p>
<pre class="css">.col {
	float: left; }
.gutter {
	margin-right: 12px; }
.span1 {
	width: 120px; }
.span2 {
	width: 252px; }
.span3 {
	width: 384px; }
.span4 {
	width: 516px; }
.span5 {
	width: 648px; }
.span6 {
	width: 780px; }
.clear {
	clear: left; }</pre>
<p>Pretty simple stuff, right? All it contains is nine classes that I can arbitrarily assign to my structural divs to determine how the page will lay out. The first class, &#8220;col&#8221;, gets assigned to any div I want to behave like a column. </p>
<p>Then each column is given one of the &#8220;span&#8221; classes (using <a href="http://www.cssnewbie.com/css-rules-multiplicity/">the benefit of multiple CSS classes to great effect</a>) to determine its width &mdash; or as I thought of it at the time, the number of columns the div would span&#8230; just like using &#8220;colspan&#8221; in old-school table layouts. </p>
<p>Next up we have the &#8220;gutter&#8221; class, which I add to any column that should have a gutter along its right edge (which would be true for all columns except those along the very right edge of my content area). And finally, there&#8217;s a &#8220;clear&#8221; class, just to ensure that my divs behave themselves even if I didn&#8217;t entirely fill up the previous &#8220;row&#8221; of divs.</p>
<h3>The XHTML Structure</h3>
<p>There&#8217;s not much to the XHMTL structure for my custom framework. Essentially, it&#8217;s a bunch of divs given two or more of my nine classes to determine its behavior. For example, to create the 4-2/2-1-3 structure I highlighted in the image above, this would be the structure:</p>
<pre class="html">&lt;div class=&quot;col span4 gutter&quot;&gt;Four columns&lt;/div&gt;
&lt;div class=&quot;col span2&quot;&gt;Two columns here&lt;/div&gt;
&lt;div class=&quot;col span2 gutter&quot;&gt;Two cols and a gutter&lt;/div&gt;
&lt;div class=&quot;col span1 gutter&quot;&gt;Only 120px!&lt;/div&gt;
&lt;div class=&quot;col span3&quot;&gt;Three columns.&lt;/div&gt;</pre>
<p>If you&#8217;d like to see this sort of custom framework in action, it&#8217;s running on <a href="http://www.woodsmithshop.com/?from=cssnewbie">the website for the Woodsmith Shop TV show.</a></p>
<h3>One Size Doesn&#8217;t Fit All</h3>
<p>Now, I&#8217;m not saying my framework is the end-all CSS framework and that you should just copy it wholesale into your own project and expect it to work perfectly. The idea here is to take this concept and come up with a custom framework that works perfectly for <em>your needs</em>. </p>
<p>The real take-away lesson here is that for most projects, you don&#8217;t need dozens of classes and hundreds of lines of CSS just to create a flexible grid structure. I created mine with just nine CSS classes and it was sufficient to power my six-column grid. I&#8217;d be interested to see what other people (namely, you) have come up with along these same lines. Share a link in the comments!</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/cssnewbie?a=tnYaQWMZqgo:wQEuYOLiEro:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/cssnewbie?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/cssnewbie?a=tnYaQWMZqgo:wQEuYOLiEro:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/cssnewbie?i=tnYaQWMZqgo:wQEuYOLiEro:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/cssnewbie?a=tnYaQWMZqgo:wQEuYOLiEro:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/cssnewbie?i=tnYaQWMZqgo:wQEuYOLiEro:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/cssnewbie?a=tnYaQWMZqgo:wQEuYOLiEro:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/cssnewbie?i=tnYaQWMZqgo:wQEuYOLiEro:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/cssnewbie?a=tnYaQWMZqgo:wQEuYOLiEro:l6gmwiTKsz0"><img src="http://feeds.feedburner.com/~ff/cssnewbie?d=l6gmwiTKsz0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/cssnewbie?a=tnYaQWMZqgo:wQEuYOLiEro:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/cssnewbie?i=tnYaQWMZqgo:wQEuYOLiEro:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/cssnewbie/~4/tnYaQWMZqgo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.cssnewbie.com/build-custom-frameworks/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.cssnewbie.com/build-custom-frameworks/</feedburner:origLink></item>
		<item>
		<title>CSS Art: The Flower</title>
		<link>http://feedproxy.google.com/~r/cssnewbie/~3/MCUXArNNR8A/</link>
		<comments>http://www.cssnewbie.com/css-art-the-flower/#comments</comments>
		<pubDate>Tue, 24 Feb 2009 02:33:22 +0000</pubDate>
		<dc:creator>Rob Glazebrook</dc:creator>
		
		<category><![CDATA[Box Model]]></category>

		<category><![CDATA[CSS Art]]></category>

		<category><![CDATA[Floats and Positioning]]></category>

		<category><![CDATA[art]]></category>

		<category><![CDATA[css]]></category>

		<category><![CDATA[positioning]]></category>

		<guid isPermaLink="false">http://www.cssnewbie.com/?p=380</guid>
		<description><![CDATA[This article is probably not the most practical tutorial I've ever written, but it was one of the most fun. While CSS is often treated as a straightforward web development workhorse, it can also have a lighthearted, eccentric side as well. Here's how to use CSS to create art.]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.cssnewbie.com/example/css-art/flower.html"><img src="http://www.cssnewbie.com/wp-content/uploads/2009/02/css-art-flower.gif" alt="css art flower" title="css art flower" width="579" height="258" class="alignnone size-full wp-image-381" /></a></p>
<p>Today’s article is probably not the most practical tutorial I’ve ever written, but it was definitely one of the most fun to create. It also shows that, while CSS is often treated as a straightforward web development workhorse (and it’s a great workhorse, at that), it can also have a lighthearted, eccentric side as well. Today’s tutorial is about how to use CSS to create art.</p>
<p>Now, as I’ve mentioned numerous times, I am not an artist. If true CSS artists were likened to Salvador Dali or someone similar, I’d be more akin to the guy watching Bob Ross on public television and following along at home, creating wobbly little smudges and pretending they’re happy little trees. But! What my example above (and <a href="http://www.cssnewbie.com/example/css-art/flower.html">you can skip ahead and see the final version</a>) shows is that it doesn’t take very many CSS rules to create some pretty cool CSS art.<span id="more-380"></span></p>
<p>And the best part about tackling CSS art is you’re likely to learn a lot about CSS along the way. Sure, this art form is probably only a step or two above the ASCII art generated in the nineties – but playing around with ASCII art taught me a decent bit about letter forms, line lengths and the rest. Likewise, practicing CSS art will teach you an awful lot about sizing, positioning and the use of color to create an effect.</p>
<p><strong>To warn:</strong> my example flower makes extensive use of the border-radius property (which <a href="http://www.cssnewbie.com/easy-rounded-corners-with-border-radius/">I’ve covered more in-depth here</a>), which doesn’t work in Internet Explorer. The net result is that the IE version of my flower looks a bit Atari-esque&#8230; but the rest of the code still works fine.</p>
<p>So let’s get to the code!</p>
<h3>The XHTML</h3>
<p>I’ve attempted to keep my code as simple as possible, while still keeping each of my flower’s segments separated for easy adjustment. Here’s what my code looks like:</p>
<pre class="html">&lt;div id=&quot;background&quot;&gt;
	&lt;div id=&quot;flower&quot;&gt;
		&lt;div id=&quot;topleft&quot; class=&quot;petal&quot;&gt;&lt;/div&gt;
		&lt;div id=&quot;topright&quot; class=&quot;petal&quot;&gt;&lt;/div&gt;
		&lt;div id=&quot;center&quot;&gt;&lt;/div&gt;
		&lt;div id=&quot;bottomleft&quot; class=&quot;petal&quot;&gt;&lt;/div&gt;
		&lt;div id=&quot;bottomright&quot; class=&quot;petal&quot;&gt;&lt;/div&gt;
		&lt;div id=&quot;leftleaf&quot; class=&quot;leaf&quot;&gt;&lt;/div&gt;
		&lt;div id=&quot;stem&quot;&gt;&lt;/div&gt;
		&lt;div id=&quot;rightleaf&quot; class=&quot;leaf&quot;&gt;&lt;/div&gt;
	&lt;/div&gt;
&lt;/div&gt;</pre>
<p>The “background” div creates the blue sky and green grass, while the “flower” div contains the rest of my work. Each petal and leaf gets its own ID, while each group shares a class to reduce the number of rules I have to write. The stem and center circle are unique, and thus don’t have a class assigned.</p>
<p>I’ve written my code in the same order that it is to appear on the screen (assuming I move top to bottom, left to right). However, if you were willing to make more extensive use of positioning than I have, you could conceivably place the individual divs in any order you so chose.</p>
<h3>The CSS</h3>
<p>And now for the fun part! I’ll break my CSS into several parts so you can see how it all comes together. First, we’ll set up the background and the main flower div:</p>
<pre class="css">#background {
	position: relative;
	background-color: #9cf;
	width: 600px;
	height: 476px;
	border-bottom: 10px solid #090;
	margin: 0 auto; }
#flower {
	position: absolute;
	top: 20px;
	left: 172px;
	width: 256px; }</pre>
<p>The background has been relatively positioned so that I can absolutely position my flower inside it, using <a href="http://www.cssnewbie.com/harnessing-positioning-1/">the relative-absolute positioning trick.</a> I’ve also given it a width and height, to provide my image’s frame. Then I’ve used a background color to simulate the blue sky and a border to provide the ground. My flower is absolutely positioned (which also means it becomes the containing div for any positioned divs nested inside), and is placed on top of the background.</p>
<p>Then we have the flower petals:</p>
<pre class="css">.petal {
	background-color: #f33;
	float: left;
	margin: 1px 1px 0 0;
	width: 125px;
	height: 125px;
	-moz-border-radius: 20px;
	-webkit-border-radius: 20px; }
#topleft {
	-moz-border-radius-bottomright: 0;
	-webkit-border-bottom-right-radius: 0;
	border-bottom: 2px solid #c33;
	border-right: 2px solid #c33; }
#topright {
	-moz-border-radius-bottomleft: 0;
	-webkit-border-bottom-left-radius: 0;
	border-bottom: 2px solid #c33;
	border-left: 2px solid #c33;  }
#bottomleft {
	-moz-border-radius-topright: 0;
	-webkit-border-top-right-radius: 0;
	border-top: 2px solid #c33;
	border-right: 2px solid #c33; }
#bottomright {
	-moz-border-radius-topleft: 0;
	-webkit-border-top-left-radius: 0;
	border-top: 2px solid #c33;
	border-left: 2px solid #c33; }</pre>
<p>This is the largest chunk of CSS (because each petal is slightly different), but it’s fairly repetitive in nature (because each petal is fundamentally the same). The “petal” class sets our basic rules: our petals are dark red, floated left, have a tiny bit of space on their top and left sides, are 125 pixels wide and tall, and have rounded corners.</p>
<p>The following four sets of rules simply specialize each of the petals to make them unique. I’m doing two things. First, I’m removing the curved border on the innermost corner; technically the center circle covers almost the entire inner corner, but it looks cleaner without the curve, and it also allows me to resize the center area without worrying about whether the curved border will show through. Then I’m adding a 2-pixel wide darker red border to the inner two sides of the flower petals, which adds a sense of depth and a bit of visual interest.</p>
<p>Next we have the center circle and the stem:</p>
<pre class="css">#center {
		position: absolute;
		left: 112px;
		top: 112px;
		background-color: #ff3;
		width: 30px;
		height: 30px;
		-moz-border-radius: 15px;
		-webkit-border-radius: 15px; }
	#stem {
		float: left;
		width: 12px;
		height: 200px;
		margin: 0 1px;
		background-color: #093; }</pre>
<p>Although the center area looks like a circle, like all XHTML elements, it is technically a rectangle. This particular rectangle is a square, 30 pixels wide and tall. And then all I’ve done is given each side a 15 pixel border radius, resulting in a perfect circle. Once the circle was made, I used absolute positioning to center the circle over the intersection of the four flower petals.</p>
<p>The stem was the most straightforward of my elements. It’s a true unrounded rectangle, given a green background color, a width, height, and margin, then floated left so I could place my leaves directly against it without having to resort to absolute positioning.</p>
<p>And speaking of the leaves, here’s how they were created:</p>
<pre class="css">.leaf {
	float: left;
	margin-top: 80px;
	background-color: #093;
	width: 60px;
	height: 30px; }
#leftleaf {
	clear: left;
	margin-left: 10px;
	-moz-border-radius-bottomleft: 30px;
	-webkit-border-bottom-left-radius: 30px;
	-moz-border-radius-topright: 30px;
	-webkit-border-top-right-radius: 30px; }
#rightleaf {
	-moz-border-radius-bottomright: 30px;
	-webkit-border-bottom-right-radius: 30px;
	-moz-border-radius-topleft: 30px;
	-webkit-border-top-left-radius: 30px; }</pre>
<p>I was particularly proud of how the leaves turned out, even though they’re fairly simple in design. The leaf class sets some defaults: they’re floated left, given a top margin to push them down the stem, the background color matches the stem color, and the width and height give them a long, slender (if blocky) appearance.</p>
<p>The individual leaf IDs are what make them look so nice. Each leaf has two rounded corners on opposite sides. The rounded corners continue for exactly half the width of the box. The result is a very visually appealing curve. The left leaf also received two additional treatments: it gets a clear to ensure it doesn’t show up to the right of the petals, and has a left margin to push the stem exactly where I wanted it.</p>
<p><a href="http://www.cssnewbie.com/example/css-art/flower.html">And that’s all there is to this flower!</a> Even though it may seem complex, I’ve really only used a dozen or so CSS properties in a variety of different ways. As I said, this is a great exercise to tackle in order to gain a greater understanding of how positioning elements works (and it’s a lot of fun for the border-radius property as well).</p>
<h3>Additional Challenges</h3>
<p>So <a href="http://www.cssnewbie.com/example/css-art/flower.html">that’s what I was able to accomplish</a> in less than 100 lines of code. So what can you do? I encourage you to show me up and share links to your masterpieces in the comments below. Here are some suggestions for challenges:</p>
<ul>
<li>Recreate my flower using proportional units instead of pixels. That would allow you to resize the flower and still keep it looking pretty!</li>
<li>With a bit of absolute positioning and more rounded corners, try adding clouds to the otherwise bland background.
<li>My flower’s leaves remind me of cat eyes. Try creating a cat or similar beast using pure CSS.</li>
</ul>
<p>And no matter what: have fun!</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/cssnewbie?a=6qGqiOJ5"><img src="http://feeds.feedburner.com/~f/cssnewbie?d=41" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=1Pyp9xlm"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=1Pyp9xlm" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=bHnLA28d"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=bHnLA28d" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=RbsbtSBG"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=RbsbtSBG" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=v2v9N9Fj"><img src="http://feeds.feedburner.com/~f/cssnewbie?d=54" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=LxX1gncb"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=LxX1gncb" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/cssnewbie/~4/MCUXArNNR8A" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.cssnewbie.com/css-art-the-flower/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.cssnewbie.com/css-art-the-flower/</feedburner:origLink></item>
		<item>
		<title>Get SitePoint Books, Give to a Worthy Cause</title>
		<link>http://feedproxy.google.com/~r/cssnewbie/~3/zC5s1M8YPOY/</link>
		<comments>http://www.cssnewbie.com/get-sitepoint-books-give-to-a-worthy-cause/#comments</comments>
		<pubDate>Wed, 11 Feb 2009 21:07:49 +0000</pubDate>
		<dc:creator>Rob Glazebrook</dc:creator>
		
		<category><![CDATA[Resources]]></category>

		<category><![CDATA[books]]></category>

		<category><![CDATA[css books]]></category>

		<category><![CDATA[design books]]></category>

		<guid isPermaLink="false">http://www.cssnewbie.com/?p=374</guid>
		<description><![CDATA[SitePoint is having a 5-for-1 book sale to raise money for victims of the Australian bushfires ravaging the countryside there. This offer ends this Friday, so act quickly!]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.boston.com/bigpicture/2009/02/bushfires_in_victoria_australi.html"><img src="http://www.cssnewbie.com/wp-content/uploads/2009/02/bushfires.jpg" alt="Bushfires in Victoria, Australia. AP photo found on Boston.com." title="Bushfires in Victoria, Australia. AP photo found on Boston.com." width="579" height="231" class="alignnone size-full wp-image-375" /></a></p>
<p>Every once in a while, a deal comes around that is sort of a no-brainer. <a href="http://5for1.aws.sitepoint.com/">This is one of those deals,</a> so I suggest you read, act, and enjoy (in that order)!</p>
<p><a href="http://www.sitepoint.com/">SitePoint</a> is a well-respected online media company that, among other things, publishes some very well written books. I received a copy of <a href="http://www.amazon.com/gp/product/0975841963?ie=UTF8&#038;tag=cssnewbie-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=0975841963">Jason Beaird’s <em>The Principles of Beautiful Web Design</em></a> for Christmas, and I couldn&#8217;t put it down until I finished it – despite the fact that I also had a shiny new copy of Mario Kart Wii vying for my attention. That’s a good web book, people.</p>
<p>SitePoint&#8217;s home offices are based in Melbourne, Australia – which is in the Victoria state in the southeast corner of the continent, for those of you who (like me) aren’t the best at geography. As you’ve probably seen in the news, <a href="http://www.boston.com/bigpicture/2009/02/bushfires_in_victoria_australi.html">Victoria is currently battling the worst bushfires in Australian history.</a></p>
<p>So where does the whole books/cause thing figure in?<span id="more-374"></span></p>
<p>In order to raise money for the Australian Red Cross, <a href="http://5for1.aws.sitepoint.com/">SitePoint is having a 5-for-1 sale on PDF versions of their books.</a> You can purchase and download high-quality PDF versions of five of their books for just $29.95 (normally $149.75 total!). And best of all, <strong>100% of your purchase will go to the Australian Red Cross and will help victims of the bushfires.</strong> </p>
<p>This offer ends on this Friday (February 13th), so be sure to act fast. I’ll be getting my five books momentarily – as soon as I can narrow down my list to my top five picks! Which five books are you picking up? Let me know in the comments.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/cssnewbie?a=dQtt1X0z"><img src="http://feeds.feedburner.com/~f/cssnewbie?d=41" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=TRmRnyan"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=TRmRnyan" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=hFXuMbBF"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=hFXuMbBF" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=ZcJjZCYp"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=ZcJjZCYp" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=UE4Z6bpu"><img src="http://feeds.feedburner.com/~f/cssnewbie?d=54" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=U5wM4y2D"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=U5wM4y2D" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/cssnewbie/~4/zC5s1M8YPOY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.cssnewbie.com/get-sitepoint-books-give-to-a-worthy-cause/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.cssnewbie.com/get-sitepoint-books-give-to-a-worthy-cause/</feedburner:origLink></item>
		<item>
		<title>How to Fix WordPress Feedburner Plugins After Converting to Google Feedburner</title>
		<link>http://feedproxy.google.com/~r/cssnewbie/~3/hMJRFdLHIzg/</link>
		<comments>http://www.cssnewbie.com/how-to-fix-wordpress-feedburner-plugins-after-converting-to-google-feedburner/#comments</comments>
		<pubDate>Mon, 09 Feb 2009 22:04:05 +0000</pubDate>
		<dc:creator>Rob Glazebrook</dc:creator>
		
		<category><![CDATA[Bugs and Fixes]]></category>

		<category><![CDATA[Quick Tip]]></category>

		<category><![CDATA[bug fix]]></category>

		<category><![CDATA[feedburner]]></category>

		<category><![CDATA[fix]]></category>

		<category><![CDATA[google]]></category>

		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://www.cssnewbie.com/?p=369</guid>
		<description><![CDATA[Google has been converting all Feedburner user accounts into Google accounts, which has been creating quite a few headaches. I thought I was done with them, until I noticed my counts still weren't showing up on my website. Google had changed the API, requiring a fix on my end.]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.cssnewbie.com/wp-content/uploads/2009/02/feedburner-api.gif" alt="Feedburner API" title="Feedburner API" width="579" height="150" class="alignnone size-full wp-image-370" /></p>
<p>I ran into (yet another) Feed Count + Feedburner problem recently, shortly after writing my last article on <a href="http://www.cssnewbie.com/fixing-a-bad-feedburner-subscriber-count/">accounting for Feedburner’s subscriber count mistakes.</a> And since I heard from a few people who are also using the Feed Count plugin, I thought I should share this info.</p>
<h3>The Backstory</h3>
<p>As I’m sure all you Feedburner users out there are well aware, <a href="http://www.feedburner.com/google">Google purchased Feedburner</a> quite some time ago. But until recently, that didn’t mean much: the same people were working on the code, your information was stored in the same place and was represented the same way, and so on.</p>
<p>But recently Google has begun bringing Feedburner more fully into the fold. As a result, all Feedburner users are being required to convert their Feedburner accounts into Google accounts. That created quite a few headaches for lots of people (including myself) right off the bat, as it took a good week for Google to nail down my subscriber numbers with any accuracy – one day I would have thousands of subscribers, the next I might have zero, and the day following only a few hundred.<span id="more-369"></span></p>
<h3>A New Problem</h3>
<p>However, even once Google started reporting my Feedburner numbers correctly, I still had a problem: <strong>my Feed Count plugin no longer grabbed my subscription statistics.</strong> Now, this wasn’t as huge a problem as it could have been, because I had <a href="http://www.cssnewbie.com/fixing-a-bad-feedburner-subscriber-count/">my jQuery Feeburner fix</a> in place&#8230; but I still wanted my real subscriber stats back at some point.</p>
<p>After a bit of digging, I found the problem: as part of their conversion from Feedburner to “Google” Feedburner, <strong>Google changed <a href="http://code.google.com/apis/feedburner/awareness_api.html">the location of their API.</a></strong> Thus, any plugins that used the old Feedburner API ceased functioning once that user’s account was successfully ported to Google.</p>
<h3>The Solution</h3>
<p>Long-term, the best solution would be for the plugin developers to update and release new versions of their plugins. But as of now, the Feed Count plugin has not been updated – and since <a href="http://www.mapelli.info/tags/plugin/feedcount">it hasn’t seen an update since last July,</a> I’m not going to hold my breath on a new version. So I decided to take matters into my own hands and edit my copy of the Feed Count plugin.</p>
<p><strong>Note:</strong> this solution is specific to the Feed Count plugin, but any brave souls out there could probably modify and use this information to update other plugins as well.</p>
<p>I opened up my copy of the Feed Count plugin file (feedcount.php) and found this function:</p>
<pre class="php">function mapelli_fc_get_defaults() {
	return array(
			'map_fc_feedurl' =&gt; '',
		  'map_fc_queryurl' =&gt;'http://api.feedburner.com/awareness/1.0/GetFeedData?uri=',
			'map_fc_lastcount' =&gt; 'N/A',
			'map_fc_lastupdate' =&gt; 0,
			'map_fc_updateinterval' =&gt; 60, // 1 h
	    'map_fc_error_updateinterval' =&gt; 5, // 5 min
		  );
}</pre>
<p>This function mostly sets all the plugin defaults, but it also sets the “queryurl” – the website that the plugin hits to find your subscriber count information. This URL is not customizable anywhere inside Wordpress, and since this URL has now changed, we’re forced to edit the plugin itself. </p>
<p>All I had to do was change the “map_fc_queryurl” line to read this instead:</p>
<pre class="php">'map_fc_queryurl' =&gt;'https://feedburner.google.com/api/awareness/1.0/GetFeedData?uri=',</pre>
<p>Then I saved the plugin, uploaded it to my server, and my stats started showing up again! However, it’d still recommend putting something like <a href="http://www.cssnewbie.com/fixing-a-bad-feedburner-subscriber-count/">this JavaScript fix</a> in place for those random times when Feedburner drops the ball (and your subscriber count).</p>
<p><strong>Note:</strong> Your stats probably won’t start showing up again instantly. You’ll have to wait for the duration of your “update interval,” which can be configured in WordPress under Settings -&gt; Feed Count:</p>
<p><img src="http://www.cssnewbie.com/wp-content/uploads/2009/02/feedcount-update-interval.gif" alt="feedcount update interval" title="feedcount update interval" width="579" height="61" class="alignnone size-full wp-image-371" /></p>
<p>If you’re using a different plugin and have run into this same problem, please give this solution a try and let people know in the comments if it worked. Thanks! </p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/cssnewbie?a=eIYYgJIp"><img src="http://feeds.feedburner.com/~f/cssnewbie?d=41" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=2SfwDU3C"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=2SfwDU3C" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=4lUSUFy5"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=4lUSUFy5" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=FnYo1381"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=FnYo1381" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=iV6PaYAE"><img src="http://feeds.feedburner.com/~f/cssnewbie?d=54" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=bKExzACB"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=bKExzACB" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/cssnewbie/~4/hMJRFdLHIzg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.cssnewbie.com/how-to-fix-wordpress-feedburner-plugins-after-converting-to-google-feedburner/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.cssnewbie.com/how-to-fix-wordpress-feedburner-plugins-after-converting-to-google-feedburner/</feedburner:origLink></item>
		<item>
		<title>Advanced jQuery Tabbed Box Techniques</title>
		<link>http://feedproxy.google.com/~r/cssnewbie/~3/n2Q-B9_CNQI/</link>
		<comments>http://www.cssnewbie.com/advanced-jquery-tabbed-box-techniques/#comments</comments>
		<pubDate>Sun, 25 Jan 2009 20:06:17 +0000</pubDate>
		<dc:creator>Rob Glazebrook</dc:creator>
		
		<category><![CDATA[Advanced Techniques]]></category>

		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[Navigation]]></category>

		<category><![CDATA[advanced]]></category>

		<category><![CDATA[css]]></category>

		<category><![CDATA[interface]]></category>

		<category><![CDATA[jquery]]></category>

		<category><![CDATA[tabbed box]]></category>

		<category><![CDATA[tutorial]]></category>

		<category><![CDATA[ui]]></category>

		<guid isPermaLink="false">http://www.cssnewbie.com/?p=363</guid>
		<description><![CDATA[Last week's article covered how to build a tabbed box interface, starting with Photoshop, and moving through XHTML and CSS to our basic jQuery functionality. If you missed it, I would highly recommend starting your reading there. This article will show you how to use jQuery to make your tabbed interface more attractive and interactive.]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.cssnewbie.com/example/tabbed-box/advanced.html"><img src="http://www.cssnewbie.com/wp-content/uploads/2009/01/tabbed-animated.gif" alt="animated tabbed box interface" title="animated tabbed box interface" width="579" height="200" class="alignnone size-full wp-image-364" /></a></p>
<p><a href="http://www.cssnewbie.com/build-a-tabbed-box-with-css-and-jquery/">Last week’s article</a> covered how to build a tabbed box interface, starting with Photoshop, and moving through XHTML and CSS to our basic jQuery functionality. If you missed it, I would highly recommend starting your reading there. This article will show you how to use jQuery to make your tabbed interface more attractive and interactive. Specifically, I’ll show you how to:</p>
<ul>
<li>Make your tabs all the same height</li>
<li>Automatically rotate through your tabbed content</li>
<li>Stop the rotation when the user is interacting with the content</li>
</ul>
<h3>Equal Height Tabs</h3>
<p>The tabbed interface we built last week was fully functional, but one nicety I’d like to add is the option to have all your tabs be the same height – a height that is determined by the content within the tabs, not any number I arbitrarily determine in advance.<span id="more-363"></span></p>
<p>While there are several ways to calculate and apply height in jQuery, the fastest and easiest means to our end would be to use <a href="http://www.cssnewbie.com/equalheights-jquery-plugin/">the equalHeights jQuery plugin I developed and wrote about recently.</a> By using that plugin, we’d only have to make a single addition to the “document ready” portion of our jQuery:</p>
<pre class="js">$(".tabbed-content").equalHeights();</pre>
<p>This will cycle through all of our tabbed content divs and equalize their heights based on the height of the tallest div. The benefit of this is the content around our tabbed box won’t shift up or down each time the user switches tabs, resulting in a more pleasant visual experience.</p>
<h3>Rotate Through Tabbed Content</h3>
<p>While tabbed boxes like the one we’ve built are a great way to fit a large amount of content in a small space, they do have one drawback: many users never click through the tabs to see what all is offered, meaning they only ever see the content on the first tab. My proposed solution to this problem is to automatically rotate through the tabs.</p>
<p>This solution has two benefits: first, the movement is more likely to catch the users’ eyes, increasing the chances they’ll notice the tabbed box in the first place. Second, it allows your users to see all the content your box contains instead of just the first tab.</p>
<p>Making this adjustment to our jQuery requires edits in several areas, so I’ll show you the new code in its entirety before explaining what it all does:</p>
<pre class="js">var currentTab = 0;
var rotateSpeed = 5000;
var numTabs;.
var autoRotate;

function openTab(clickedTab) {
	var thisTab = $(&quot;.tabbed-box .tabs a&quot;).index(clickedTab);
	$(&quot;.tabbed-box .tabs li a&quot;).removeClass(&quot;active&quot;);
	$(&quot;.tabbed-box .tabs li a:eq(&quot;+thisTab+&quot;)&quot;).addClass(&quot;active&quot;);
	$(&quot;.tabbed-box .tabbed-content&quot;).hide();
	$(&quot;.tabbed-box .tabbed-content:eq(&quot;+thisTab+&quot;)&quot;).show();
	currentTab = thisTab;
}

function rotateTabs() {
	var nextTab = (currentTab == (numTabs - 1)) ? 0 : currentTab + 1;
	openTab($(&quot;.tabbed-box .tabs li a:eq(&quot;+nextTab+&quot;)&quot;));
}

$(document).ready(function() {
	$(&quot;.tabbed-content&quot;).equalHeights();
	numTabs = $(&quot;.tabbed-box .tabs li a&quot;).length;

	$(&quot;.tabbed-box .tabs li a&quot;).click(function() {
		openTab($(this)); return false;
	});

	autoRotate = setInterval(&quot;rotateTabs()&quot;, rotateSpeed);
	$(&quot;.tabbed-box .tabs li a:eq(&quot;+currentTab+&quot;)&quot;).click()
});</pre>
<p>The first variable, currentTab, is unchanged from our first iteration. But then we’ve added three new variables:</p>
<ul>
<li>rotateSpeed is the number of milliseconds to wait before switching tabs.</li>
<li>numTabs is a variable that will contain the total number of tabs in our box. We’re initializing it at the beginning so we can use it in all our functions.</li>
<li>autoRotate is a variable we’ll use later.</li>
</ul>
<p>Our openTab function hasn’t changed. If you’d like to understand how it works, <a href="http://www.cssnewbie.com/build-a-tabbed-box-with-css-and-jquery/">please refer to the first article.</a></p>
<p>Next we’ve written a new function called rotateTabs. This function will handle the math required to determine which tab should be opened next. First we set a new variable, nextTab. What we set nextTab to depends on which tab we’re on currently. The function looks at currentTab: if currentTab is our last tab in the list, it starts back over at the beginning (the tab with an index of 0). Otherwise, nextTab is simply the next tab in the list. Once we’ve determined our next tab, we call the openTab function, which prevents us from having to duplicate all that heavy lifting.</p>
<p>We’ve added two lines to our document ready function.  The first sets the numTabs variable to be the number of tabs in our box. We don’t populate this variable until the document is ready, because otherwise it will try to count the tabs before our tabs have loaded and will return a length of -1 (aka, none found). </p>
<p>The second bit we added is towards the end, where we set autoRotate. In autoRotate we’re calling the JavasScript setInterval function, which executes a piece of JavaScript on a regular interval. As we’ve written it, we will be calling our autoRotate function every “rotateSpeed” milliseconds. This means that when our document loads, it will wait that many milliseconds, then switch to the next tab, then pause again, then switch again infinitely. </p>
<p>Pretty neat, huh? <a href="http://www.cssnewbie.com/example/tabbed-box/rotate.html">You can see this functionality in action here.</a></p>
<h3>Stopping the Rotation</h3>
<p>Now, automatically rotating your tabs is a pretty awesome effect, but at some point you’re probably going to want that rotation to stop. Specifically, you don’t want your tabs switching when your users are interacting with them. </p>
<p>I tested several scenarios on when and how to stop the tabs from rotating before deciding on how I’m doing it here. It only requires editing a couple of lines from our document ready function:</p>
<pre class="js">$(document).ready(function() {
	$(&quot;.tabbed-content&quot;).equalHeights();
	numTabs = $(&quot;.tabbed-box .tabs li a&quot;).length;
	$(&quot;.tabbed-box .tabs li a&quot;).click(function() {
		openTab($(this)); return false;
	});
	$(&quot;.tabbed-box&quot;).mouseover(function(){clearInterval(autoRotate)})
	.mouseout(function(){autoRotate = setInterval(&quot;rotateTabs()&quot;, rotateSpeed)});

	$(&quot;.tabbed-box .tabs li a:eq(&quot;+currentTab+&quot;)&quot;).click()
	$(&quot;.tabbed-box&quot;).mouseout();

});</pre>
<p>Here we’ve replaced our setInterval function with something a little more complex. We’re now using both setInterval and clearInterval (which stops setInterval), and we’re applying them when the user’s mouse interacts with our tabbed box. </p>
<p>Specifically, we’re letting the box auto-rotate whenever the mouse is nowhere near the box, and stopping the box from rotating whenever the mouse is over the box. This means that as long as the user has the mouse over the box, as if they were reading, or clicking through the tabs, or clicking on something inside one of our tabs, the tabs wouldn’t switch on them. But as soon as they’re done interacting with the box, it’ll switch back to its regular rotation.</p>
<p>This does require one extra line at the end of the script, to force a “mouseout” event on the tabbed box, which gets things rotating by default.</p>
<p><a href="http://www.cssnewbie.com/example/tabbed-box/advanced.html">You can see our fully functional tabbed interface here.</a> Give it a try: watch it rotate through, and then try interacting with the box a bit. You’ll see that the tabs don’t automatically move, as long as you’re actively engaged with the box.</p>
<p>And that’s that! I hope you’ve found this mini-series helpful, and I’d love to see how you’ve implemented this idea on your own websites. Drop me a line in the comments below if you do.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/cssnewbie?a=dlApjTbZ"><img src="http://feeds.feedburner.com/~f/cssnewbie?d=41" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=Ga18tUIB"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=Ga18tUIB" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=QKSqVJ0h"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=QKSqVJ0h" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=PszvO2cJ"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=PszvO2cJ" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=uG8nJa4O"><img src="http://feeds.feedburner.com/~f/cssnewbie?d=54" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/cssnewbie?a=ov5Phrfp"><img src="http://feeds.feedburner.com/~f/cssnewbie?i=ov5Phrfp" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/cssnewbie/~4/n2Q-B9_CNQI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.cssnewbie.com/advanced-jquery-tabbed-box-techniques/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.cssnewbie.com/advanced-jquery-tabbed-box-techniques/</feedburner:origLink></item>
	</channel>
</rss>
