CSS for a range of elements
Styling a range of elements. Here from the 1st to the 3rd one - changing background color. Example:
HTML code:
<div> </div>
<div> </div>
<div> </div>
<div> </div>
CSS code:
div:nth-of-type(-n+3) {background: #f66;}
Note: nth-child may also be used instead.
Browser support
- Windows
- Internet Explorer 9.0+
- Firefox 1.5+
- Google Chrome
- Opera 9.5+
- Safari 3.1+
- SeaMonkey 1.0+
- Linux
- Firefox 1.5+
- Google Chrome / Chromium
- Opera 9.5+
- SeaMonkey 1.0+