<?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>Cow Computing &#187; HTML5</title>
	<atom:link href="http://www.cowcomputing.com/tag/html5/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cowcomputing.com</link>
	<description>Share Info about Cloud Computing &#38; Programming</description>
	<lastBuildDate>Thu, 22 Jul 2010 17:10:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>HTML 5 nth-Child</title>
		<link>http://www.cowcomputing.com/2010/02/07/html-5-nth-child/</link>
		<comments>http://www.cowcomputing.com/2010/02/07/html-5-nth-child/#comments</comments>
		<pubDate>Sun, 07 Feb 2010 08:45:15 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML5]]></category>

		<guid isPermaLink="false">http://www.cowcomputing.com/?p=174</guid>
		<description><![CDATA[As we all know, HTML 5 is on its way, and there&#8217;s going to be a huge addition to the current syntax. In this post, i shall share with you about the &#8220;nth-child&#8221; feature. Often, we would like to create a table or list with alternate row color as follow: // HTML Snippet &#60;div id="test-area"&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>As we all know, HTML 5 is on its way, and there&#8217;s going to be a huge addition to the current syntax. In this post, i shall share with you about the &#8220;nth-child&#8221; feature. Often, we would like to create a table or list with alternate row color as follow:</p>
<pre class="brush:html">// HTML Snippet
&lt;div id="test-area"&gt;
  &lt;ul&gt;
    &lt;li&gt;row 1&lt;/li&gt;
    &lt;li class="even-row"&gt;row 2&lt;/li&gt;
    &lt;li&gt;row 3&lt;/li&gt;
    &lt;li class="even-row"&gt;row 4&lt;/li&gt;
    &lt;li&gt;row 5&lt;/li&gt;
    &lt;li class="even-row"&gt;row 6&lt;/li&gt;
    &lt;li&gt;row 7&lt;/li&gt;
    &lt;li class="even-row"&gt;row 8&lt;/li&gt;
    &lt;li&gt;row 9&lt;/li&gt;
    &lt;li class="even-row"&gt;row 10&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</pre>
<pre class="brush:css">// CSS Snippet
ul {
  list-style: none;
}

// color the even rows
.even-row {
  background-color: #ccc;
}
</pre>
<p><span id="more-174"></span>The above method is okay when you are working with simple rule, but how about if i only want 1, 7, 13, 19&#8230;(6n+1)th rows to be highlighted. Then you probably need to write some javascript and do calculation to do it. However, with HTML 5, we got a better yet easier way to accomplish this. We will be using the new property &#8220;nth-child&#8221;. Let me illustrate by rewriting the example above:</p>
<pre class="brush:html">// HTML Snippet
&lt;div id="test-area"&gt;
  &lt;ul&gt;
    &lt;li&gt;row 1&lt;/li&gt;
    &lt;li&gt;row 2&lt;/li&gt;
    &lt;li&gt;row 3&lt;/li&gt;
    &lt;li&gt;row 4&lt;/li&gt;
    &lt;li&gt;row 5&lt;/li&gt;
    &lt;li&gt;row 6&lt;/li&gt;
    &lt;li&gt;row 7&lt;/li&gt;
    &lt;li&gt;row 8&lt;/li&gt;
    &lt;li&gt;row 9&lt;/li&gt;
    &lt;li&gt;row 10&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</pre>
<pre class="brush:css">// CSS Snippet
ul {
  list-style: none;
}

// Note that n is a special symbol here
li:nth-child(2n) {
  background-color: #ccc;
}
</pre>
<p>See the power of nth-child? We now no longer need to label alternate rows, instead, we use the nth-child property. We simply tell nth-child with the calculation (e.g. any integers like &#8220;1&#8243;, &#8220;3&#8243;, &#8220;5&#8243; or using the special &#8220;n&#8221; variable for help, like: &#8220;2n&#8221; representing alternative rows, &#8220;5n&#8221; representing every fifth rows or even the word &#8220;odd&#8221; and &#8220;even&#8221;&#8230; you might try to edit the code above to use &#8220;even&#8221; instead of &#8220;2n&#8221; to accomplish the same effect.), and it will apply the CSS for you. To learn more, you might try the <a href="http://www.cowcomputing.com/demo/nth-child-demo/">demo page</a> i made.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cowcomputing.com/2010/02/07/html-5-nth-child/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
