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 760191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:41:15+00:00 2026-05-14T15:41:15+00:00

I am designing a 960px wide layout with an unordered list. Each list item

  • 0

I am designing a 960px wide layout with an unordered list. Each list item is 240px wide, so 4 list items fit horizontally in a row. I have about 20 rows on the page….

I want every other list item to have a background of #ececec, so my css would be:

ul li:nth-child(2n+2){
    background-color:#ececec;
}

This works. The only problem is because there are 4 items in a row (an even #), the next row would be identical, thus rendering background colors on every 1st and 3rd list items in a row. This is not the effect I am looking to achieve. I want the background colors to alternate, creating a grid-like effect. What is the correct css to do so (think a checker board). Thanks!

  • 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-05-14T15:41:15+00:00Added an answer on May 14, 2026 at 3:41 pm

    If you want a checkerboard, then use:

    ul li:nth-child(8n+1), ul li:nth-child(8n+3), ul li:nth-child(8n+6), ul li:nth-child(8n+8) {
        background-color:#ececec;
    }
    

    The pattern repeats every two rows, which in your case is every 8 elements, so you need 8n in the selector. And of those eight, you want the 0th, 2nd, 5th and 7th to have the alternate color.

    EDIT: I tried this HTML, and got a checkerboard in Firefox 3.5.9:

    <html>
    <head>
    <style>
    #container {
        width: 960px;
        border: 1px solid black;
    }
    span {
        border: 1px solid gray;
        display: block;
        width: 180px;
        float: left;
        padding: 10px;
        margin: 10px;
        background: blue;
    }
    span:nth-child(8n+1), span:nth-child(8n+3), span:nth-child(8n+6), span:nth-child(8n+8) {
        background: red;
    }
    </style>
    <body>
    <div id='container'>
        <span>One</span>
        <span>Two</span>
        <span>Three</span>
        <span>Four</span>
        <span>Five</span>
        <span>Six</span>
        <span>Seven</span>
        <span>Eight</span>
        <span>Nine</span>
        <span>Ten</span>
        <span>Eleven</span>
        <span>Twelve</span>
        <span>Thirteen</span>
        <span>Fourteen</span>
        <span>Fifteen</span>
        <span>Sixteen</span>
        <span>Seventeen</span>
        <span>Eighteen</span>
    </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

whilst designing the about page for my new service, i have stumbled across a
When designing user table what would be the must have fields from the security/user
While designing applications it is a very good practice to have all the business
When designing an rdlc report using the VS 2010 report designer, report items such
im designing a system where i will have multiple users uploading large amount of
When designing a new J2EE based enterprise framework, do I have to prepare for
Designing a simple HTML table that I am going to implement alternate-row coloring on...
When designing my application how many controllers should I have? Is it good practice
I have a layout defined through CSS that has three columns. It displays correctly
When designing for layout and styling with CSS, it might be useful to add

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.