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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:44:48+00:00 2026-06-13T21:44:48+00:00

How can i use css or jquery to add border-top only on the first

  • 0

How can i use css or jquery to add border-top only on the first row in a table?

I’m using the code below to get border on every td, but i need a border for the first row on top as well.

I cannot use CSS3 in this project btw.

What i have:

content


content


content


What i want:


content


content


content


.MyCarTable td {
    border-bottom: 1px solid grey;
}
  • 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-13T21:44:49+00:00Added an answer on June 13, 2026 at 9:44 pm

    Everything can be done with CSS only which is in this case preferred way becuase of performance reasons. Don’t use javascript unless you actually have to because it can’t be done in any other way.

    Solution 1: use first-child pseudo class

    Add additional style definition.

    .MyCarTable td {
        border-bottom: 1px solid #ccc;
    }
        .MyCarTable tr:first-child td {
            border-top: 1px solid grey;
        }
    

    And don’t worry. This particular pseudo class has been long supported in browsers. Even IE supports it since version 7. Here’s a JSFiddle that shows this working.

    Solution 2: table header using th elements

    If your table has header row, then use th elements instead of td in it and set different styling for header cells. But use this only when semantic content of your first row cells is actually cell header description for rows underneath. Otherwise I wouldn’t suggest it.

    Consecutive tables problem

    If you have consecutive tables within the same container then next tables get top borders from previous table’s last row. And you don’t want them to apply top border on first row because that duplicates borders.

    The solution (as seen in this JSFiddle) is similar and also applies to first table only:

    .MyCarTable td {
        border-bottom: 1px solid #ccc;
    }
        .MyCarTable:first-child tr:first-child td {
            border-top: 1px solid #f99;
        }​
    

    As you can see top row’s borders are only set for first table and first row within it. All consecutive tables won’t set it. This example is of course only compatible with first solution above. If you’d taken the path with th elements then a combination of both should be used (th and pseudo classes).

    But as you’ve said you’ve consolidated your repeater code.

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

Sidebar

Related Questions

Please see the jQuery below: I am really wondering how can I use CSS
You can use the URL helper in Code Igniter to load CSS and Javascript
How can i use Jquery to add a class on user selection? My Aspx
hi i am using jquery i want to add css color with important property
If I have a collection of div elements, I can use CSS to have
Well, question is in title. Is it possible at all? I can use css
What is a library I can use for CSS webkit support across multiple browsers
I have defined CSS in MasterPage so that all pages can use the same
I can use FireFox and FireBug, in a pane, I can open a .css
How can I link .scss files to be automatically use css color scheme?

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.