Pseudo Pseudo Classes

The :first-child and :last-child pseudo classes in CSS are super-handy for stying things like lists. For example, if you want a horizontal line between list items, you can set:

ul li {
  border-bottom: solid 1px #e0e0e0;
}
ul li:last-child {
  border: none;
}

Unfortunately, most current browsers can’t stomach :first-child and :last-child. :(

But just a teaspoon of jQuery will make that pseudo-class medicine go right down:

function firstLast()
{
  $('ul li:first-child').addClass('first');
  $('ul li:last-child').addClass('last');
}
jQuery(firstLast);

comment feed And the ensuing discussion…

  1. 1

    Feb 23rd, 2009 at 7:47 am sonictruth

    Wow, thats a great idea. I work with drupal which tends to give me first and last classes on list items, however I often find myself wanting first and last classes on p tags. This will work a treat.

    Thanks

Comments are closed.



Additional Resources


Tumblelog

Tumblr

Tumblr

Delicious

Delicious

Instructional

Recent Instructional Articles

Slicehost (and Linode) LAMP Cheatsheet

17.11
16

A quick list of steps I use to set up a LAMP server on Slicehost or Linode.

Terminal Tip: Prevent Creation of Mac Dot Files

07.08
2

An environment variable can prevent creation of ._filename files.

Terminal Tip: Delete Those Mac Dot Files

08.06
4

Use the find command to delete all of the ._* and .DS_Store files.

Editorial

Recent Editorial Articles

More Usable Mac: Finder Toolbar

05.12
3

I find it useful to keep a few extra items in my Finder toolbar.

No Multiple-Class Support in IE6

18.11
9

IE6 doesn’t respond to multiple class selectors.

New Skin for the Old Blogish

07.10
8

This blogish is finally back online after an extended period of http silence.

Downloadable

Recent Downloadable Articles

Gitup!

01.02
0

Gitup + Transmit = Really Simple Publishing

Leopard-Style iTerm Icon, Take 2

18.12
8

The newer, bluer version of the iTerm icon.

Leopard-Style iTerm Icon

05.12
6

An updated, Leopard-style icon for iTerm.

About This Site

About the Author

That’s me in the photo above. My current profession is web development. Therefore, it is the subject of this site.

Postpostmodern

Postpostmodern is the name of this site and my alias on most of the web. There's nothing really special about the name Postpostmodern. I studied art in college during the years after postmodernism, and nobody knew how else to classify the state of things other than silly words like postpostmodernism.

Sorta Blogish

I'd call this a blog, but I don't feel it fits the 'log' format. My goal is to publish articles on web-related topics that interest me, and while some articles may be time-sensitive, I would prefer that the organizational focus be on the categories and tags rather than chronology.

More Me

More about me can be found on the about page. Or, look me up in the usual places: