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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:11:28+00:00 2026-06-03T09:11:28+00:00

Given a list of elements like this: <ul> <li class=favourite></li> <li class=favourite></li> <li class=favourite></li>

  • 0

Given a list of elements like this:

<ul>
  <li class="favourite"></li>
  <li class="favourite"></li>
  <li class="favourite"></li>
  <li></li>
  <li></li>
  <li></li>
</ul>

I would like to create a gap between the list elements which have .favourite and those which don’t.

Is there a way I can do this with CSS?

Edit
Assume that elements with the class .favourite are always forced to the top of the list.

  • 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-03T09:11:29+00:00Added an answer on June 3, 2026 at 9:11 am

    You can apply a margin to a li that’s not .favourite, that comes right after a li.favourite. You will need to use :not() in conjunction with an adjacent sibling selector, like this:

    li.favourite + li:not(.favourite) {
        margin-top: 1em;
    }
    

    If it’s not known in your actual markup whether classless elements come first or li.favourite elements come first, and you want to create a gap regardless of the order, extend the selector like this to cover both cases:

    li.favourite + li:not(.favourite), li:not(.favourite) + li.favourite {
        margin-top: 1em;
    }
    

    Use a left margin instead of a top margin if your list flows horizontally from left to right.

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

Sidebar

Related Questions

Given a list of elements like so: int[] ia = new int[] { -4,
Given a list like this: num = [1, 2, 3, 4, 5] There are
Say I have a simple class like this: public class ReferenceChanger<T> { public T
This exercise is taken from Google's Python Class : D. Given a list of
How do I get a tuple/list element given a condition in python? This occurs
This portion of code checks if a number given (First element in a list)
Given a list of numbers, how does one find differences between every ( i
Given a List<int> myValues which I know to be ordered, what is the quickest
I have defined a C#-class, that shall be the elements of a directed graph
I have got ul-li list in which there is a span element inside all

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.