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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:08:49+00:00 2026-05-28T04:08:49+00:00

I have 2 divs <div id=number1><div id=number2></div></div> Why is #number1 { background:red; } #number2

  • 0

I have 2 divs

<div id=number1><div id=number2></div></div>

Why is

#number1 {
    background:red;
}

#number2 {
   background:blue;
   height: 200px;
   margin: 10px;
}

Not the same as

#number1 {
    background:red;
    padding:10px;
}

#number2 {
   background:blue;
   height: 200px;
}

And in the first case I get white lines at the top & bottom, where it is suppose to be the red color of div 1?
http://jsfiddle.net/ZbCNq/

  • 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-05-28T04:08:49+00:00Added an answer on May 28, 2026 at 4:08 am

    In the first case, the unexpected behaviour you’re experiencing is due to “collapsing margins”.

    The spec:

    • http://www.w3.org/TR/CSS2/box.html#collapsing-margins
    • http://www.w3.org/TR/css3-box/#collapsing-margins

    Some easier reads:

    • http://complexspiral.com/publications/uncollapsing-margins/
    • http://reference.sitepoint.com/css/collapsingmargins
    • http://www.howtocreate.co.uk/tutorials/css/margincollapsing

    You could fix it by:

    • Using padding on #number1 instead of margin on #number2, as you’ve done in your question.
    • Adding overflow: hidden to #number1: http://jsfiddle.net/thirtydot/EWeDE/1/
    • Adding some padding to #number1: http://jsfiddle.net/thirtydot/EWeDE/2/
    • Adding float: left; width: 100% to #number1: http://jsfiddle.net/thirtydot/EWeDE/3/
    • Adding display: inline-block; width: 100%; to #number1: http://jsfiddle.net/thirtydot/EWeDE/4/
    • Adding a border to #number1: http://jsfiddle.net/thirtydot/EWeDE/5/
    • I’m sure there are more ways.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have multiple divs in my body which need the same style: <div class=box></div>
I have 3 divs inside 1 div like so.. <div class=contentImages> <div id=slideshow> <img
I have two MAIN DIVs inside a DIV which is a PART of the
I have two divs: <div class=outer> <div class=inner>Example</div> </div> And I have a jQuery
I have two divs: <div class=dialog large></div> and <div class=dialog></div> I have to remove
I have some divs: <div class=A>Target</div> <div class=A B>NotMyTarget</div> <div class=A C>NotMyTarget</div> <div class=A
So I have 3 divs contained inside a containing div like such: <div id=contain>
I have 8 divs. Each div has the class 'pre-loader'. In addition to thas
I have three divs, within a content div. Container width 70%. Within that I
I have multiple DIVs with unique IDs. Each DIV onclick slides down and shows

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.