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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:43:05+00:00 2026-06-02T05:43:05+00:00

If you have the HTML: <section class=column> <p> Some Test </p> <p> Some Test

  • 0

If you have the HTML:

<section class="column">
  <p> Some Test </p>
  <p> Some Test </p>
  <p> Some Test </p>
</section>

<section class="column">
  <p> Some More Test </p>
  <p> Some More Test </p>
  <p> Some More Test </p>
</section>

<section class="someotherclass">
  <p> Some More Test </p>
  <p> Some More Test </p>
  <p> Some More Test </p>
</section>

and CSS:

.column:last-child { background:red; }

http://jsfiddle.net/WYu24/

Is there a way to make the :last-child selector pick up the last occurrence of a class?

  • 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-02T05:43:07+00:00Added an answer on June 2, 2026 at 5:43 am

    Currently there is no shortcut syntax or pseudo-class in CSS for finding the first or last child having a certain class.1

    I use an overriding technique to style the first child with a certain class, which I describe in heavy detail in this answer. However, due to how sibling combinators work, this technique cannot be applied for the last child having a certain class.

    I do not know of any pure CSS way to target the last child having a certain class. You have to use JavaScript or restructure your markup in order to do that. If there is exactly one such element, then using jQuery you can simply use the :last selector to add a class, which you can then style with CSS:

    $('.column:last').addClass('last');
    
    .column.last { background:red; }
    

    jsFiddle preview


    1 There are some new pseudo-classes being proposed in Selectors 4 which would fit the bill, but browsers won’t start implementing it for another few months or until the spec is more stable, and even then we don’t know if these pseudo-classes are going to stick because the current syntax looks rather awkward:

    :nth-last-match(1 of .column) { background:red; }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have html and css as below - .title { display: block; background-color: red;
I have the following construct in my HTML document: <div class=content> <section class=column></section> <aside
I have the following HTML: <DIV class=foo bar></DIV> I'm trying to create a CSS
Is this possible? you can se my problem here: http://granjalaaurora.com/test/test-jscrollpane.html I have this structure:
Assume that I have some HTML page, and a corresponding CSS file. I'd like
I have the following html <div class=section> <div>header</div> <div> contents <div>sub contents 1</div> <div>sub
First off I am completely new to Javascript but I have some HTML/CSS experience.
I have a base.html which has a login section at the top of every
I have 11 checkboxes in my HTML form and already have a section in
I have a website which slides to a section called blog in my HTML.

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.