homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / CSS
Forum Library, Charter, Moderators: not2easy

CSS Forum

Style every second/alternate div
:nth-child() or :nth-of-type() selectors

5+ Year Member

Msg#: 4256652 posted 4:36 pm on Jan 22, 2011 (gmt 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.



WebmasterWorld Senior Member 5+ Year Member

Msg#: 4256652 posted 11:22 am on Jan 24, 2011 (gmt 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+.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / CSS
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved