Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

CSS3 element1~element2 selector

CSS3 element1~element2 Selector

Complete CSS SelectorComplete CSS Selector Reference Manual

Example

Set the background color of every ul element that follows a p element with the same parent:

p~ul

{

background:#ff0000;

}

Try it »


Definition and Usage

element1~element2 The selector matches element2 that appears after element1.

element1 and element2 Both elements must have the same parent, but element2 element2 does not have to immediately follow element1 element1.


Browser support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support element1~element2 selector.

**Note:** To use this selector in IE8 and earlier versions, a DOCTYPE must be declared .


Complete CSS SelectorComplete CSS Selector Reference Manual