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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:03:59+00:00 2026-06-14T08:03:59+00:00

In a page I have many HTML tables that have many columns in them.

  • 0

In a page I have many HTML tables that have many columns in them. I need to apply different styles on them. All columns will have different width but in tables they will same, by this I mean first column of all tables will be same, same is for second and all columns.

CSS is applied on tables but not on columns, is there a way I just add css classes and I may have not to apply them in html code and they are applied automatically. May be using
pseudocolumns or any other way ?

  • 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-14T08:04:00+00:00Added an answer on June 14, 2026 at 8:04 am

    If you’re able to use browsers that support CSS nth-child(), you can use:

    tr td:nth-child(even) {
        background-color: #ffa;
    }
    

    JS Fiddle demo.

    In the above demo I’ve used :nth-child(even) to avoid styling the first of the td elements (which contains the row-heading), you could, of course, contain the row heading in a th element (which would probably be more semantically correct), or, to style the odd columns (or the odd td elements) but not the :first-child, the :not() selector is available:

    tr td:nth-child(odd):not(:first-child) {
        background-color: #ffa;
    }
    

    JS Fiddle demo.

    If you’re limited by having to support older browsers, that don’t support the :nth-child() pseudo-class, you can use the adjacent-sibling selector (though this is less maintainable):

    td + td, /* styles the second td */
    td + td + td + td { /* styles the fourth td */
        background-color: #ffa;
    }
    
    td + td + td { /* styles the third td */
        background-color: #fff;
    }
    

    JS Fiddle demo.

    Thoug it’d be easier to style with classes (even if only provided for the odd (or the even):

    .even { /* styles the cells with the class of 'even' */
        background-color: #ffa;
    }
    
    .even + td { /* styles the cell that follows the cell with the 'even' class */
        background-color: #f90;
    }
    

    You could also use the colgroup and col elements to define classes for your columns:

    <table>
        <colgroup>
            <col class="first" />
            <col class="second" />
            <col class="third" />
            <col class="fourth" />
        </colgroup>
        <thead>
            <tr>
                <th></th>
                <th>Column one</th>
                <th>Column two</th>
                <th>Column three</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>Row one</td>
                <td>row one, cell one</td>
                <td>row one, cell two</td>
                <td>row one, cell three</td>
            </tr>
            <tr>
                <td>Row two</td>
                <td>row two, cell one</td>
                <td>row two, cell two</td>
                <td>row two, cell three</td>
            </tr>
        </tbody>
    </table>
    

    With the following CSS as an example (note there’s no reason not to style the other col classes, I just chose not to in this demo):

    .second, .fourth {
        background-color: #ffa;
    }​
    

    JS Fiddle demo.

    References:

    • Adjacent-sibling (+) combinator.
    • col.
    • colgroup.
    • :first-child.
    • :not().
    • :not() compatibility, at Quirksmode.
    • :nth-child().
    • :nth-child() compatibility, at Quirksmode.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an HTML page that has many nested tables, for example table for
I have a web-site that generates some simple tabular data as html tables, many
I have a page designed with many HTML Tables which are hidden or displayed
my problem is : I have a page with several html tables that I
I have an html page with many tables. <html> <table> POINTER_TEXT some other stuff
how can i do. i have many html elements on page. after clicking on
Suppose on my HTML page I have many href s to a link. Using
If I have a single page with many forms of existing records: index.html.haml -
In our HTML page, we have a list of tags to load in many
I am doing a registration page coding. For that i have so many fields

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.