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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:24:46+00:00 2026-06-07T14:24:46+00:00

I have different tables that are similar but the only difference is that they

  • 0

I have different tables that are similar but the only difference is that they may have different cols.
I want to define a style that if the number of columns is say 2, then the width of first td be 80% and width of second one be 105. If the table has three columns, their width should be 45%, 45% and 10% and so on.

How can I do it in CSS? If it is not possible to do it in CSS, how can I do it in JQuery?

  • 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-07T14:24:47+00:00Added an answer on June 7, 2026 at 2:24 pm

    That’s, as far as I know, not doable just with CSS since you need to calculate percentages and detect the number of columns.

    I set up a fiddle with a jQuery example, assuming the same number of columns for each row (no colspan used). Here’s how I did it:

    var cols       = $('table tr:first td').size(),
        width      = 90 / cols,
        last_width = 10;
    
    $('table td').css('width', width + "%");
    $('table tr > td:last-child').css('width', last_width + "%");
    ​
    

    The vars used are the number of columns, the last column size, and the other columns size (90% of width by number of columns). Then we apply the resulting width to all the cells, and the last column width to the last cell of each row.

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

Sidebar

Related Questions

I have five tables that are fairly similar in structure but different enough that
I have 4 different tables that I want to join. The tables are structured
I've 3 different database tables that have the same 5 fields but those does
I have four different tables, one main SPECIAL table containing only id's that reference
I have a LINQ to SQL DataContext that queries four different tables. But I
Person has two similar tables, difference is that each person has only one record
I have two similar methods that basically does the same thing only with different
I have 2 similar tables on different databases. I already linked the remote DB
I have 3 different sql environments which are similar but not same. I have
I have a few objects that are incredibly similar. In fact, they use STI

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.