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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:00:20+00:00 2026-06-13T19:00:20+00:00

This might be due to margin collapsing and I know about margin collapsing, at

  • 0

This might be due to margin collapsing and I know about margin collapsing, at least how it affects adjacent elements, but I don’t understand how it works on nested elements when negative margins are involved.

For example, in this markup and accompanying CSS:

Markup

<div class="parent">
  <div class="child">
    Child 1
  </div>
</div>

<div class="parent">
  <div class="child negative">
    Child 1
  </div>
</div>

CSS

body {
  background: white;
  padding: 45px;
}

.parent {
  border: 1px solid black;
  margin-bottom: 10px;
}

.negative {
  margin-bottom: -1px;
}

Live example here.

When I inspect the height of the second .parent div, I notice it is 1 pixel less than the first one. This has happened because of the negative margin on the .negative element inside it. I had a quick look at W3C and couldn’t find an explanation for this behavior.

Could someone please explain what’s happening here and also provide me with a link to the W3C spec section about it?

  • 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-13T19:00:21+00:00Added an answer on June 13, 2026 at 7:00 pm

    This might be due to margin collapsing and I know about margin collapsing, at least how it affects adjacent elements, but I don’t understand how it works on nested elements when negative margins are involved.

    Section 8.3.1 has all the details. It also covers the behavior of adjoining margins between nested boxes, as well as negative margins.

    However, what you’re seeing here is not the effect of margin collapse because you have negated it with a border: 1px solid black declaration in your .parent rule. That means having a border there prevents your .parent margin from collapsing with your .child.negative margin altogether.

    Rather, this is simply how negative margins work. This is covered in various sections of the visual formatting model, but it’s most succinctly and directly addressed in the beginning of Section 11, which summarizes it thus:

    Generally, the content of a block box is confined to the content edges of the box. In certain cases, a box may overflow, meaning its content lies partly or entirely outside of the box, e.g.:

    • …
    • A descendant box has negative margins, causing it to be positioned partly outside the box.

    So what’s happening here, instead, is:

    1. The absolute value of the .child.negative element’s negative margin is subtracted from the .parent element’s actual height (by 1px).

    2. As a result, the .child.negative element itself overflows .parent (because its own height is not changed and the default overflow for any div is visible).

    3. Since margin collapse does not take effect here, the margin-bottom: 10px in your .parent is unaffected. Note that while any subsequent elements in normal flow will be shifted up by 1px, this is mainly due to the negative margin of your .child.negative element; in other words, a side effect of step 1.

    And that’s all there is to it.

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

Sidebar

Related Questions

because I manually want to show the modal popup (this might be due to
This might seem like a very easy question for some of you folks, but
This might be a simple question but I've searched and searched and can't find
This might be a naive question. However, I am just trying to understand why
This might be a very basic question but it confuses me. Can two different
This might sound like a stupid question but just trying to learn something here.
This might have to be broken down a bit but what i want to
This might be a general mvp places and activities question, but the show case
This might sound rudimentary but, I have created tables by running queries in Workbench
This might be a silly question, but... I've been writing a number of classes

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.