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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:46:50+00:00 2026-06-18T04:46:50+00:00

How can I target some child elements except where the parent is the first

  • 0

How can I target some child elements except where the parent is the first or last child to its parent?

See the comments in my CSS for a better idea of what I mean.

CSS:

/* Always apply */
tr th, tr td
{
    text-align: left;
    vertical-align: top;
}

/* Apply to all except first <tr> */
tr th, tr td
{
    padding-top: 5px;
}

/* Apply to all except last <tr> */
tr th, tr td
{
    border-bottom: 1px solid #c4c4c4;
    padding-bottom: 5px;
}

HTML:

<table>
    <tr>
        <th>Born</th>
        <td><time datetime="1986-11-05">5<sup>th</sup> November 1986</time></td>
    </tr>
    <tr>
        <th>Gender</th>
        <td>Male</td>
    </tr>
    <tr>
        <th>Sports</th>
        <td>Football<br />Tennis</td>
    </tr>
    <tr>
        <th>Teams</th>
        <td>Liverpool FC<br />Spain FC</td>
    </tr>
</table>
  • 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-18T04:46:51+00:00Added an answer on June 18, 2026 at 4:46 am

    Well you have a solution in the questions you linked. Use the :not() pseudo-class:

    /* Apply to all except first <tr> */
    tr:not(:first-child) th, tr:not(:first-child) td{
        padding-top: 5px;
    }
    
    /* Apply to all except last <tr> */
    tr:not(:last-child) th, tr:not(:last-child) td{
        border-bottom: 1px solid #c4c4c4;
        padding-bottom: 5px;
    }
    

    fiddle

    (this won’t work in IE 8 though)


    Alternative for IE 7+, if the border styles can change:

    /* Apply to all */
    tr th, tr td{
        border-top: 1px solid #c4c4c4;
        padding-top: 5px;
    }
    
    /* Remove styles from first */
    tr:first-child th, tr:first-child td{
        border-top: 0;
        padding-top: 0;
    }
    

    or

    /* Apply to all but first */
    tr + tr th, tr + tr td{
        border-top: 1px solid #c4c4c4;
        padding-top: 5px;
    }
    

    (but not sure if + is supported by IE 7)

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

Sidebar

Related Questions

I have written some CSS which targets elements using the parent > child selector.
For the following image html: <img src=/some.png alt=something /> In CSS, you can target
jQuery can select the Child of something, or Parent, or next tag. Does C#
I have a nav with some child a -elements. I added a click function
I have a list of <li> elements, and I'm using :nth-child to target specific
I know in Visual Studio 2008 you can target a specific framework with your
I want to develop a program in c# that can target and application or
I'm trying to change the color of the Asterisk but I can't target the
How can I specifically target Android < 3.0 in either vanilla JS or jQuery?
Normally we can specify a target in the link or use javascript window.open to

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.