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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:05:18+00:00 2026-06-11T12:05:18+00:00

I want to zebra stripe only select tables using. I do not want to

  • 0

I want to zebra stripe only select tables using. I do not want to use jQuery for this.

tbody tr:nth-child(even) td, tbody tr.even td {background:#e5ecf9;}

When I put that in a css file it affects all tables on all pages that call the same stylesheet. What I would like to do is selectively apply it to specific tables.

I have tried this, but it doesn’t work.

// in stylesheet
.zebra_stripe{
    tbody tr:nth-child(even) td, tbody tr.even td {background:#e5ecf9;}    
}

// in html
<table class="zebra_even">
<colgroup>
    <col class="width_10em" />
    <col class="width_15em" />
</colgroup>
<tr>
    <td>Odd row nice and clear.</td>
    <td>Some Stuff</td>
</tr>
<tr>
    <td>Even row nice and clear but it should be shaded.</td>
    <td>Some Stuff</td>
</tr>
</table>

And this:

<table>
    <colgroup>
        <col class="width_10em" />
        <col class="width_15em" />
    </colgroup>
    <tbody class="zebra_even">

The stylesheet works as it is properly formatting other elements of the html. Can someone help me with an answer to this problem?

  • 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-11T12:05:19+00:00Added an answer on June 11, 2026 at 12:05 pm

    Your code looks like this:

    .zebra_stripe{
        tbody tr:nth-child(even) td, tbody tr.even td {background:#e5ecf9;}    
    }
    

    This is wrong (obviously, or you wouldn’t need to ask the question), but isn’t that far off.

    The solution is that you simply need to include .zebra_stripe in the existing CSS selectors. CSS doesn’t support multiple tiers of selectors in braces, the way you wrote it. (there are other dialects like Less and Sass that do support this kind of syntax, if you really need it, but in your case the solution doesn’t need any clever syntax)

    .zebra_stripe tbody tr:nth-child(even) td, .zebra_stripe tbody tr.even td {
        background:#e5ecf9;
    }
    

    This assumes you have a table with the class zebra_stripe:

    <table class='zebra_stripe'>
        ....
    </table>
    

    Tables without the class won’t be striped.

    By the way, I’ve left both your selectors in there, but you shouldn’t need them both. The nth-child() selector should do the trick on its own, without the tr.even alternative. The tr.even would be needed in browsers that don’t support nth-child() (ie old versions of IE), but in that case, if you need to support them, you’d do it with the even class, and wouldn’t need to use nth-child().

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

Sidebar

Related Questions

I want to zebra-stripe a html table without using any js stuff or writing
I'm using the jquery Tablesorter with the zebra widget for my table. I want
I need some help with zebra striping a table using jQuery. I want the
i want to draw zebra lines in my form not a table, just lines
I have a question form that I want to validate using jquery. My form
I want to apply a zebra striping style to my mx:List, the only way
i wrote a jquery function and now i want to use it as a
I have a gridview which I want to zebra stripe after it has been
I want to give a zebra stripe effect to my table rows. In all
want to drag element to specific div and if not dragged to this div

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.