1. Computing & Technology

Discuss in my forum

Adjacent Sibling Selectors

Precise Definitions of CSS Styles

By , About.com Guide

Cascading Style Sheets defines siblings as elements that are next to one another. They are also called adjacent elements. This means that you can define a style rule on an element based on what element immediately precedes it in the XHTML.

How to define a sibling rule:
  h1 + h2 { color : #00f; }

This rule says that any h2 that immediately follows an h1 should be colored blue.

Browser Support

The adjacent sibling 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.

©2012 About.com. All rights reserved.

A part of The New York Times Company.