homepage Welcome to WebmasterWorld Guest from 54.211.180.175
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
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
greencode




msg:4256654
 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.

 

alt131




msg:4257225
 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