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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:54:08+00:00 2026-06-10T08:54:08+00:00

I have a scenario where I have multiple DIV stacked together with both margin-top

  • 0

I have a scenario where I have multiple DIV stacked together with both margin-top and margin-bottom, but I found the margin-bottom ignored when I have margin-top. I couldn’t explain how it happens.

html

<div class='box'>
<div class='item'>1</div>
<div class='item'>2</div>
<div class='item'>3</div>
<div class='item'>4</div>
<div class='item'>5</div>
<div class='item'>6</div>
<div class='item'>7</div>
<div class='item'>8</div>
</div>​

css

.box{
    width:100%;
    height:300px;

}

.item{
    list-style: none;
    display:block;
    margin-top:20px;
    margin-bottom:20px;
    width:100%;
    height:50px;                
    background-color:red;
}

If I set the item to float:left, then it able to disable margin-bottom properly.

CSS by div floating left

.item{
    list-style: none;
    float:left;
    display:block;
    margin-top:20px;
    margin-bottom:20px;
    width:100%;
    clear:both;
    height:50px;                
    background-color:red;
}     ​

Here’s the jsfiddle link to illustrate it better. Tested with chrome and firefox. Could someone explain how it happens?

  • 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-10T08:54:10+00:00Added an answer on June 10, 2026 at 8:54 am

    To elaborate on my somewhat terse comment:

    Imagine you have code like this:

    <body>
        <p>A paragraph</p>
        <p>Another paragraph</p>
        <p>A final paragraph</p>
    </body>
    

    and your CSS is:

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

    If the margin-collapsing didn’t happen, you’d end up with a 10 pixel margin at the top, and a 10 pixel margin at the bottom, but 20 pixel margins between the paragraphs which is often not what was required.

    To solve this, the browser collapses the top and bottom margins into each other so the gap between the paragraphs (or any other block-level elements) is equal to the larger of the top and bottom margins.

    That’s what’s happening with your code.

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

Sidebar

Related Questions

Let me try and explain the scenario: I have a form with multiple items
I have a scenario where multiple users will be doing import processes, but all
We have a scenario where multiple devices are connected to one com port. Each
The Scenario: We have multiple nodes distributed geographically on which we want to have
I have a scenario where I have to update multiple rows in a table
I have a scenario in which I have to run multiple commands one after
Imagine the scenario you have a listing page that is a concatenation of multiple
I am having a scenario, in which i have multiple delegates attached to the
Here's a scenario... I have a column. In the column i have multiple divs
I have scenario, I have two update panels on the page (both have update

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.