Welcome to WebmasterWorld Guest from

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)

Junior Member

10+ Year Member Top Contributors Of The Month

joined:July 4, 2007
posts: 193
votes: 0

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)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:Aug 9, 2008
posts: 961
votes: 0

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+.

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members