Stripe class for div

前端 未结 3 1379
一向
一向 2021-01-18 21:25

I have a long list of multiple div... let\'s say 20 div

All wrap in another one..

text text
相关标签:
3条回答
  • 2021-01-18 21:40

    jQuery makes it just about as easy as it can be:

    $('#main>div.xyz:even').addClass('grey');

    http://api.jquery.com/even-selector/

    0 讨论(0)
  • 2021-01-18 21:48

    If you don't care about older versions of IE, you can do this using CSS alone:

    .xyz:nth-child(odd) {
      background-color: ...;
    }
    
    .xyz:nth-child(even) {
      background-color: ...;
    }
    
    0 讨论(0)
  • 2021-01-18 21:51

    $('.xyz:odd').addClass('grey');

    Do mind that 'grey' is not a semantic classname. Better call id 'odd' or 'zebra' or something. If you'd make up your mind and change the odd color to blue your classname would be real strange :P

    0 讨论(0)
提交回复
热议问题