You are here:About>Computing & Technology>Web Design / HTML
About.comWeb Design / HTML
Newsletters & RSSEmail to a friendSubmit to Digg
All CSS Quick Tips

CSS Quick Tips

First Child Pseudo Selector

From Jennifer Kyrnin,
Your Guide to Web Design / HTML.
FREE Newsletter. Sign Up Now!

An Expansion of the CSS Child Selector

Once you have defined a child selector you can refine that selection even further using the CSS pseudo-selector first child. This allows you to add cascading style sheet styles to an even more specific element within a page.

Defining the first child:
  div > p:first-child { background-color : #00f; }

This means that the first paragraph in a div element would have the background color of blue, but the rest would keep the default background color.

Browser Support

The first-child pseudo-selector is not supported in IE 6 and lower for Windows or Netscape 4 for Windows. It did work in Safari and Internet Explorer 5.2 for Macintosh.

 All Topics | Email Article | | |
Advertising Info | News & Events | Work at About | SiteMap | Reprints | HelpOur Story | Be a Guide
User Agreement | Ethics Policy | Patent Info. | Privacy Policy©2008 About, Inc., A part of The New York Times Company. All rights reserved.