Alternating Row Colors in Bootstrap 3 - No Table

后端 未结 6 1948
天涯浪人
天涯浪人 2020-12-24 11:48

I am looking for a way to do alternating row colors in a responsive layout in Bootstrap 3. I cannot figure out how to do it without a LOT of extensive, confusing CSS and was

6条回答
  •  生来不讨喜
    2020-12-24 12:25

    Since you are using bootstrap and you want alternating row colors for every screen sizes you need to write separate style rules for all the screen sizes.

    /* For small screen */
    .row :nth-child(even){
      background-color: #dcdcdc;
    }
    .row :nth-child(odd){
      background-color: #aaaaaa;
    }
    
    /* For medium screen */    
    @media (min-width: 768px) {
        .row :nth-child(4n), .row :nth-child(4n-1) {
            background: #dcdcdc;
        }
        .row :nth-child(4n-2), .row :nth-child(4n-3) {
            background: #aaaaaa;
        }
    }
    
    /* For large screen */
    @media (min-width: 992px) {
        .row :nth-child(6n), .row :nth-child(6n-1), .row :nth-child(6n-2) {
            background: #dcdcdc;
        }
        .row :nth-child(6n-3), .row :nth-child(6n-4), .row :nth-child(6n-5) {
            background: #aaaaaa;
        }
    }
    

    Working FIDDLE
    I have also included the bootstrap CSS here.

提交回复
热议问题