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

  • Home
  • SEARCH
  • 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 51891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T16:49:17+00:00 2026-05-10T16:49:17+00:00

When you want to add whitespace between HTML elements (using CSS), to which element

  • 0

When you want to add whitespace between HTML elements (using CSS), to which element do you attach it?

I’m regularly in situations along these lines:

<body>   <h1>This is the heading</h1>   <p>This is a paragraph</p>   <h1>Here's another heading</h1>   <div>This is a footer</div> </body> 

Now, say I wanted 1em of space between each of these elements, but none above the first h1 or below the last div. To which elements would I attach it?

Obviously, there’s no real technical difference between this:

h1, p { margin-bottom: 1em; } 

…and this…

div { margin-top: 1em; } p { margin-top: 1em; margin-bottom: 1em } 

What I’m interested is secondary factors:

  1. Consistency
  2. Applicability to all situations
  3. Ease / Simplicity
  4. Ease of making changes

For example: in this particular scenario, I’d say that the first solution is better than the second, as it’s simpler; you’re only attaching a margin-bottom to two elements in a single property definition. However, I’m looking for a more general-purpose solution. Every time I do CSS work, I get the feeling that there’s a good rule of thumb to apply… but I’m not sure what it is. Does anyone have a good argument?

  • 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. 2026-05-10T16:49:17+00:00Added an answer on May 10, 2026 at 4:49 pm

    I tend to use a bottom margin on elements when I want them to have space before the next element, and then to use a ‘.last’ class in the css to remove the margin from the last element.

    <body>   <h1>This is the heading</h1>   <p>This is a paragraph</p>   <h1>Here's another heading</h1>   <div class='last'>This is a footer</div> </body> 
    div { margin-bottom: 1em; } p { margin-bottom: 1em; } h1 { margin-bottom: 1em; } .last {margin-bottom: 0; } 

    In your example though, this probably isn’t that applicable, as a footer div would most likely have it’s own class and specific styling. Still the ‘.last’ approach I used works for me when I have several identical elements one after the other (paragraphs and what-not). Of course, I cherry-picked the technique from the ‘Elements’ CSS framework.

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

Sidebar

Ask A Question

Stats

  • Questions 92k
  • Answers 92k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer We moved from VSS6 to VSS2005 just over a year… May 11, 2026 at 6:22 pm
  • Editorial Team
    Editorial Team added an answer From what I understand of your request, this should work:… May 11, 2026 at 6:22 pm
  • Editorial Team
    Editorial Team added an answer Why not just use the appropriate selector when creating the… May 11, 2026 at 6:22 pm

Related Questions

In Silverlight, when you want to create a control dynamically, you must add the
I will explain the question by example: In zend framework, when you want to
Distributing ASP.NET user controls across different projects can be really useful when you want
Suppose that for every Form in a WinForms application, you want to change the

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.