Welcome to WebmasterWorld Guest from 23.20.230.24

Forum Moderators: not2easy

Message Too Old, No Replies

Style every second/alternate div

:nth-child() or :nth-of-type() selectors

     
4:36 pm on Jan 22, 2011 (gmt 0)

5+ Year Member



Not sure why I've never had to do this before but is there any way to style every other div? I have a series of rows that are dynamically created and would like to add a different background colour to every other div row. i.e grey white grey white etc.
11:22 am on Jan 24, 2011 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



Hi Greencode, the css3 selectors :nth-child(), or :nth-of-type() would achieve what you want, but support is poor except for the most modern browsers.

If the divs already have attributes the attribute selectors [w3.org] are another option, with much wider support, including ie7+.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month