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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:40:10+00:00 2026-05-31T19:40:10+00:00

Why does every row have a red background when I’m using nth-child(odd) ? <div

  • 0

Why does every row have a red background when I’m using nth-child(odd)?

<div id="ClientTable">
    <div class="ClientTableHeaderRow"><span class="ClientTableHeaderColumn">Full Name</span></div>
    <div class="ClientTableRow"><span class="ClientName">Umpa Beeson</span></div>
    <div class="ClientTableRow"><span class="ClientName">Umpa Beeson</span></div>
    <div class="ClientTableRow"><span class="ClientName">Umpa Beeson</span></div>
    <div class="ClientTableRow"><span class="ClientName">Umpa Beeson</span></div>
</div>​
#ClientTable    {position: relative;
                 display: table;
                 margin-top: 20px;
                 width: 100%;}

#ClientTable:nth-child(odd) {background-color:#FF0000;}                 

.ClientTableHeaderRow, .ClientTableRow {display: table-row; }
.ClientTableHeaderRow {font-weight: bold;}
.ClientTableHeaderRow span, .ClientTableRow span {display: table-cell;}​

View the jsFiddle

The expected result is every other row to be red. Instead, as you can see, every row is red.
P.S. Umpa is my cat.

  • 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-31T19:40:11+00:00Added an answer on May 31, 2026 at 7:40 pm

    You should be setting ClientTableRow class, like so:

    .ClientTableRow:nth-child(odd) {background-color:#FF0000;}
    

    Demo: http://jsfiddle.net/gMR2K/4/

    EDIT

    As also explained by animuson, you need to apply the :nth-childselector to the element itself, not the parent. The name of the selector can lead one to think it will apply the styling to the children of the selected element, when actually the style is applied to n-th child of the selected element, across the whole document.

    Also, if you’re worried about browser compatibility you can also do this with JavaScript. Here’s an example using jQuery.

    $(document).ready()
    {
        $(".ClientTableRow:nth-child(odd)").addClass("redBackground");
    }
    

    Demo: http://jsfiddle.net/gMR2K/10/

    As stated here by BoltClock: jQuery “polyfills the :nth-child() selector for older browsers anyway.”

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

Sidebar

Related Questions

On large-scale Java/.Net Enterprise projects, does every developer need to have all the components/libraries/dependencies
We have a bug in our application that does not occur every time and
I have exceptions created for every condition that my application does not expect. UserNameNotValidException
Does anyone have any problems with VS2008 on Vista? For me every so often
Does anyone have an example of using a QWidget as an editor in a
So i have this table. It has some hundreds of rows. Every row has
I have a table 'Asset' with a column 'AssetDescription'. Every row of it has
Assume two tables in Oracle 10G TableA (Parent) --> TableB (Child) Every row in
I have many rows and on every row I compute the uniroot of a
Why does every time I do mvn jetty:run, maven tries to download some dependencies

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.