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

<channel>
	<title>The Bright Lines &#187; nth-of-type</title>
	<atom:link href="http://www.thebrightlines.com/tag/nth-of-type/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.thebrightlines.com</link>
	<description>HTML, CSS, Javascript and more</description>
	<lastBuildDate>Thu, 29 Jul 2010 22:44:34 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Alternative for :nth-of-type() and :nth-child()</title>
		<link>http://www.thebrightlines.com/2010/01/04/alternative-for-nth-of-type-and-nth-child/</link>
		<comments>http://www.thebrightlines.com/2010/01/04/alternative-for-nth-of-type-and-nth-child/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 21:17:14 +0000</pubDate>
		<dc:creator>Wouter Bos</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[nth-child]]></category>
		<category><![CDATA[nth-of-type]]></category>
		<category><![CDATA[zebra]]></category>

		<guid isPermaLink="false">http://www.thebrightlines.com/?p=334</guid>
		<description><![CDATA[Replace a CSS3 selector that's not supported in IE with a CSS2 selector that has support.]]></description>
			<content:encoded><![CDATA[<p><a class="button demo" href="/article-data/demo/nthChildAlternative.html"><span> </span>View demo</a></p>
<p>One thing I really like about jQuery is the ease by which you can select the <em>nth</em> item of a list of items like this: <code>jQuery("ul &gt; li:eq(3)")</code>. In CSS you would select an <em>nth</em> item like this: <code>ul &gt; li:nth-of-type(3)</code>. The problem is that <code>:</code><code>nth-of-type</code><code>()</code> is not supported at all in Internet Explorer. IE9 <em>will</em> support all CSS3 selectors, including <code>:</code><code>nth-of-type</code><code>()</code>, but by the time IE9 is a mature browser, Webkit and Gecko-based browsers are be able to do everything except your dishes.</p>
<p>So if you want to make an exception for, say, the third menu item, you have to either add a class to that menu item or select that item through Javascript. But if you don&#8217;t care for IE6, there&#8217;s a reasonable alternative:</p>
<p><code>ul &gt; li:</code><code>nth-of-type</code><code>(3)</code> equals <code>ul &gt; li:first-child + li + li</code>.</p>
<p>Although both selectors are different, they do select the same element. But the first is not supported in IE and the second <em>is</em>. From IE7 and up! Sure, it&#8217;s not feasible to select the 100th item in a list, but not all lists are that long. And you can always use Javascript as a fallback.</p>
<p>This alternative selection method is by the way by no means equal to <code>:</code><code>nth-of-type</code><code>()</code>. With <code>:</code><code>nth-of-type</code><code>()</code> you can make a cool <a href="http://www.alistapart.com/articles/zebratables/">zebra striping</a> without the use of Javascript.</p>
<p>And finally, as suggested in the title, there is also a way to handle <code>:nth-child</code><code>(3)</code> in an almost similar fashion:</p>
<p><code>ul &gt; li:</code><code>nth-child</code><code>(3)</code> equals <code>ul &gt; *:first-child + * + *</code>.</p>


<p>Related posts:<ol><li><a href='http://www.thebrightlines.com/2010/01/31/hack-how-to-enable-first-child-in-ie6/' rel='bookmark' title='Permanent Link: Hack: how to enable :first-child in IE6'>Hack: how to enable :first-child in IE6</a></li>
<li><a href='http://www.thebrightlines.com/2009/12/24/too-advanced-css-selectors/' rel='bookmark' title='Permanent Link: Too advanced CSS selectors'>Too advanced CSS selectors</a></li>
<li><a href='http://www.thebrightlines.com/2009/11/08/how-to-overcome-the-limits-of-css-in-internet-explorer-6/' rel='bookmark' title='Permanent Link: How to overcome the limits of CSS in Internet Explorer 6'>How to overcome the limits of CSS in Internet Explorer 6</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.thebrightlines.com/2010/01/04/alternative-for-nth-of-type-and-nth-child/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
