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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:41:42+00:00 2026-06-03T00:41:42+00:00

Say I have a bunch of P, LI, or DIV elements, with nothing between

  • 0

Say I have a bunch of P, LI, or DIV elements, with nothing between them. I want to control the vertical spacing between them, so they don’t fit so tightly. But I don’t want to add any space top and bottom, since that is handled by the parent element and I don’t need more. Is there a simple way to do this that works for all block elements?

Say I’ve got something like this :

p {
  margin: 5px 0;
  }

and then

 <div>
   <p>1</p>
   <p>2</p>
   <p>3</p>
   <p>4</p>
 </div>

But I don’t want 5px above p 1, or below p 4, since the div already has padding and I don’t want to go messing with that. I just want the 10px between p 1 and p 2, p 2 and p 3, etc.

I’m sure I could do something kludgy (and I have many times), but am looking for something cleaner that I don’t have to do a lot of special-casing for this common situation.

  • 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-03T00:41:45+00:00Added an answer on June 3, 2026 at 12:41 am

    Use adjacent selectors

    p + p { margin-top: 10px; }
    

    Basically the concept is that, if a p comes after another p give 10px margin in between.

    You usage is something similar to

    p + p, li + li, div + div { 
        margin-top: 10px;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say you have a bunch of elements on a webpage you don't use much,
In C++, say you have a whole bunch of objects that you want to
Let's say I have some Control that has been disabled. It contains a bunch
Let's say I have a bunch of items and I want to iterate through
Let's say I have a bunch of posts and I want to know if
Say I have a DetailsView with a bunch of fields, and I want only
Let's say I have a javascript array with a bunch of elements (anywhere from
In other words, let's say I have a bunch of divs and they're all
Say I have a bunch of objects with dates and I regularly want to
Say I have a bunch of views in a UIScrollView and I want each

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.