<?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>slash25 code &#187; css</title>
	<atom:link href="http://slash25.com/tag/css/feed/" rel="self" type="application/rss+xml" />
	<link>http://slash25.com</link>
	<description>Code that works…, Beautifully.</description>
	<lastBuildDate>Sun, 05 Feb 2012 22:35:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Using jQuery to mimic CSS3&#8242;s :nth-last-child</title>
		<link>http://slash25.com/using-jquery-to-mimic-css3s-nth-last-child/</link>
		<comments>http://slash25.com/using-jquery-to-mimic-css3s-nth-last-child/#comments</comments>
		<pubDate>Thu, 25 Jun 2009 03:59:06 +0000</pubDate>
		<dc:creator>patrick</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[CSS3]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://slash25.com/?p=216</guid>
		<description><![CDATA[I came across the need for using CSS3&#8242;s :nth-last-child pseudo-selector recently. What does this do? Nth-last-child lets you select the nth (2nd, 3rd, 4th, etc) child of some element starting from the last one. For example: To style the 2nd-to-last list item only, this example would work: The situation I had was there is a [...]]]></description>
			<content:encoded><![CDATA[<p>I came across the need for using CSS3&#8242;s <a href="http://reference.sitepoint.com/css/pseudoclass-nthlastchild">:nth-last-child pseudo-selector</a> recently. What does this do? Nth-last-child lets you select the nth (2nd, 3rd, 4th, etc) child of some element starting from the last one. For example:</p>
<pre class="qoate-code">li:nth-last-child(-n+4) //would select the last four list items in a list.</pre>
<p>To style the 2nd-to-last list item only, this example would work:</p>
<pre class="qoate-code">li:nth-last-child(-n+2)</pre>
<p>The situation I had was there is a list of authors for a site. More than <em>wp_list_authors</em>, it was a custom-generated list of certain users. The list is styled to look like a box with two columns. There are dividers between each author both horizontally and vertically, with the bottom two authors having no bottom divider.</p>
<p>This list:</p>
<pre class="qoate-code">
&lt;ul id="authors"&gt;

&lt;li class="even"&gt;&lt;a class="authorImg"&gt;
&lt;img src="avatar.jpg" alt="" height="30px" /&gt;&lt;/a&gt;
&lt;a class="authorName"&gt;John Doe&lt;/a&gt;&lt;/li&gt;

&lt;li class="odd"&gt;&lt;a class="authorImg"&gt;
&lt;img src="avatar.jpg" alt="" height="30px" /&gt;&lt;/a&gt;
&lt;a class="authorName"&gt;Hap Pill&lt;/a&gt;&lt;/li&gt;

...(snip)...

&lt;li class="odd"&gt;&lt;a class="authorImg"&gt;
&lt;img src="avatar.jpg" alt="" height="30px" /&gt;&lt;/a&gt;
&lt;a class="authorName"&gt;John Hancock&lt;/a&gt;&lt;/li&gt;

&lt;li class="even"&gt;&lt;a class="authorImg"&gt;
&lt;img src="avatar.jpg" alt="" height="30px" /&gt;&lt;/a&gt;
&lt;a class="authorName"&gt;Lorem Ipsum&lt;/a&gt;&lt;/li&gt;

&lt;li class="odd"&gt;&lt;a class="authorImg"&gt;
&lt;img src="avatar.jpg" alt="" height="30px" /&gt;&lt;/a&gt;
&lt;a class="authorName"&gt;Jane Doe&lt;/a&gt;&lt;/li&gt;

&lt;/ul&gt;
</pre>
<p>&#8230; needs to look like this:</p>
<pre class="qoate-code">
&lt;ul id="authors"&gt;
&lt;li class="even"&gt;&lt;a class="authorImg" href="#"&gt;&lt;img src="http://slash25.com/wp/wp-content/uploads/2009/06/avatar.jpg" alt="" height="30px" /&gt;&lt;/a&gt;&lt;a class="authorName" href="#"&gt;John Doe&lt;/a&gt;&lt;/li&gt;
&lt;li class="odd"&gt;&lt;a class="authorImg" href="#"&gt;&lt;img src="http://slash25.com/wp/wp-content/uploads/2009/06/avatar.jpg" alt="" height="30px" /&gt;&lt;/a&gt;&lt;a class="authorName" href="#"&gt;Hap Pill&lt;/a&gt;&lt;/li&gt;
&lt;li class="even"&gt;&lt;a class="authorImg" href="#"&gt;&lt;img src="http://slash25.com/wp/wp-content/uploads/2009/06/avatar.jpg" alt="" height="30px" /&gt;&lt;/a&gt;&lt;a class="authorName" href="#"&gt;Foo Bar&lt;/a&gt;&lt;/li&gt;
&lt;li class="odd"&gt;&lt;a class="authorImg" href="#"&gt;&lt;img src="http://slash25.com/wp/wp-content/uploads/2009/06/avatar.jpg" alt="" height="30px" /&gt;&lt;/a&gt;&lt;a class="authorName" href="#"&gt;Ima Doody&lt;/a&gt;&lt;/li&gt;
&lt;li class="even"&gt;&lt;a class="authorImg" href="#"&gt;&lt;img src="http://slash25.com/wp/wp-content/uploads/2009/06/avatar.jpg" alt="" height="30px" /&gt;&lt;/a&gt;&lt;a class="authorName" href="#"&gt;Chew Bacca&lt;/a&gt;&lt;/li&gt;
&lt;li class="odd"&gt;&lt;a class="authorImg" href="#"&gt;&lt;img src="http://slash25.com/wp/wp-content/uploads/2009/06/avatar.jpg" alt="" height="30px" /&gt;&lt;/a&gt;&lt;a class="authorName" href="#"&gt;John Hancock&lt;/a&gt;&lt;/li&gt;
&lt;li class="even"&gt;&lt;a class="authorImg" href="#"&gt;&lt;img src="http://slash25.com/wp/wp-content/uploads/2009/06/avatar.jpg" alt="" height="30px" /&gt;&lt;/a&gt;&lt;a class="authorName" href="#"&gt;Lorem Ipsum&lt;/a&gt;&lt;/li&gt;
&lt;li class="odd"&gt;&lt;a class="authorImg" href="#"&gt;&lt;img src="http://slash25.com/wp/wp-content/uploads/2009/06/avatar.jpg" alt="" height="30px" /&gt;&lt;/a&gt;&lt;a class="authorName" href="#"&gt;Jane Doe&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</pre>
<p>Removing the border on the last list item&#8217;s span is easy. Use the <em>:last-child</em> pseudo-selector and the border&#8217;s gone.</p>
<pre class="qoate-code">#authors li.odd:last-child span {
border-bottom: none;
}</pre>
<p>Removing the border on the 2nd-to-last one should be this easy:</p>
<pre class="qoate-code">#authors li:nth-last-child(-n+2) span {
border-bottom: none;
}</pre>
<p>But for now, that only works in Safari 4. (and maybe Opera?) so how to get that effect in Safari 3 and Firefox 3? (I have not gotten this to work in IE7 or 6. Those are coming.) Use jQuery and a three-line script.</p>
<p>Here&#8217;s what I cobbled together from digging through the jQuery documentation:</p>
<pre class="qoate-code">//removes bottom border from next-to-last span in the authors listings
var $curr = $('#authors li:last');
$curr = $curr.prev().children('span');
$curr.css('border-bottom','none');
</pre>
<p>The script first locates the last list item. Then it looks for the previous element of that type, then drills down to the children elements that are spans. In this case, there&#8217;s only one. Lastly, the script applies a CSS rule of no border to the span.</p>
<p>Is it perfect? Almost. I&#8217;ll need to figure out how to get IE7 and, unfortunately for this job, IE6 to render the next-to-last item correctly.</p>
]]></content:encoded>
			<wfw:commentRss>http://slash25.com/using-jquery-to-mimic-css3s-nth-last-child/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced

Served from: slash25.com @ 2012-02-06 21:00:44 -->
