Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8515505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:09:53+00:00 2026-06-11T05:09:53+00:00

I need to make every two rows of my table grey and I would

  • 0

I need to make every two rows of my table grey and I would prefer to use nth-child if possible.

I’ve messed around with Chris Coyier’s nth-child tester but still can’t get it.

I need the following formula:

1,2 - grey
3,4 - white
5,6 - grey
7,8 - white
9,10 - grey

and so on. I’d prefer not to put a class in the html as I’m sure that’s going to be a suggestion from some. If there is a way to pull this off with nth-child, that’s what I’m looking for.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T05:09:55+00:00Added an answer on June 11, 2026 at 5:09 am

    Realize that you are doing groups of 4, then you can see that you can have every 4th element and every 4th element minus one being white, then every 4th element minus two, or every 4th element minus 3 being grey.

    So, you’d use 4n and 4n-1, then 4n-2 and 4n-3:

    div:nth-child(4n), div:nth-child(4n-1) {
        background: red;
    }
    div:nth-child(4n-2), div:nth-child(4n-3) {
        background: blue;
    }
    

    That code isn’t precise to your case, I wrote it for a jsFiddle proof-of-concept.

    NB disclaimer: Keep in mind that nth-child does not work in IE8. Typical issue, of course.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've a table on where I need a spacing between two rows <tr> of
How can i make mysql start every time the system boot ? I need
I'm trying to make a game and for the gun class, I need every
I need make all of my posts update. I use bulk upload for store,
I need to make an application that will start playing same media on two
I have an EAV table (simple key/value in every row) and I need to
I need to flatten out 2 rows in a vertical table (and then join
I need to make a Javascript object that would behave as an associative array,
I need make some action (dump statistical data) before the Dart program ends. The
Need to make certain Ruby strings in my program to be immutable. What is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.