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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:29:01+00:00 2026-05-25T01:29:01+00:00

I have been searching for the past hour to find the correct CSS Selector

  • 0

I have been searching for the past hour to find the correct CSS Selector (or at least to find out if one exists) to style the elements in the DOM immediately before and after another element.

At the moment, I have a ul whose li elements have a border-bottom property. I would like to change the colour of that border if there is an element immediately after it in the DOM. If possible, I would like to avoid using separate classes for this.

Consider the following markup:

<ul>
    <li>List Item 1</li>
    <li>List Item 2</li>
    <li>List Item 3</li>
    <li class="divider">2</li>
    <li>List Item 4</li>
    <li>etc.</li>
</ul>

I would like to add border-bottom: none to <li>List Item 3</li> and any other li elements that are immediately followed by li.divider.

Is there are a CSS selector for this, something like ul > li, but for this? It doesn’t need to be cross-browser, and can be CSS3; just needs to work on WebKit browsers…

  • 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-05-25T01:29:01+00:00Added an answer on May 25, 2026 at 1:29 am

    this is not possible. there is no css selector for preceding elements; neither preceding siblings, nor ancestors.

    you can, however, apply a style to the next (and only the next) sibling:

    li.divider + li {border:1px solid black}
    

    you can chain it. this style:

    li.predivider {border-bottom: none} /*before*/
    li.predivider + li {border:1px solid black} /*divider*/
    li.predivider + li + li {border-bottom: none} /*after*/
    

    and this (combinable):

    li.divider {border:1px solid black} /*divider*/
    li.divider + li {border-bottom: none} /*after*/
    

    allows you to apply just one of either the “predivider” class, or the “divider” class, dependent of the divider being the first element (and thus has none before it) or not.

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

Sidebar

Related Questions

I have been searching for the past through days, trying to figure out how
Have been searching the net for the past hours to find a solution to
So I have been searching everywhere for the past week but I cant find
I have been searching for an answer and trying out stuff for days now
I have been searching this for quite sometime but could not find an appropriate
I have been searching everywhere but can't seem to find a solution to this
I have been searching how to put more than one function in onchange and
I have been searching for a solution for the past two days now. I
I'm out of ideas and have been searching for awhile now, so hopefully someone
I have been searching google for the past day and a half trying 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.