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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:09:52+00:00 2026-06-15T17:09:52+00:00

The follwoing html document has two divs, one with a border ( id=’with’ )

  • 0

The follwoing html document has two divs, one with a border (id='with') and one without (id='without). The div with the border is rendered (at least on firefox and chrome) significantly higher than the one with the border.

I had expected them to vary at most 2 pixels in height, yet, the alert tells me that their height is 19 pixels different.

I can’t figure out why that is.

<!DOCTYPE HTML>
<html>
<head>
  <title>Height of divs with/without a border</title>
  <script type="text/javascript" src='jquery-1.8.3.js'></script>

  <script type='text/javascript'>

    $(document).ready(function() {

           alert($('#with'   ).height() + ' / ' + 
                 $('#without').height());

    });

  </script>

</head>
<body>

  <div style='width:300px;border:black 1px solid;background-color:yellow' id='with'>
    <h1>With a border</h1>
    bla<br>
    bla<br>
    bla<br>
  </div>

  <div style='width:300px;background-color:green' id='without'>
    <h1>Without a border</h1>
    bla<br>
    bla<br>
    bla<br>
  </div>

</body>
</html>
  • 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-15T17:09:53+00:00Added an answer on June 15, 2026 at 5:09 pm

    By default, the <h1> element has a top and bottom margin and these margins are collapsed. There are rules about how the margins are collapsed (i.e. combined). The rule that applies to your example is:

    Parent and first/last child

    If there is no border, padding, inline content, or clearance to
    separate the margin-top of a block with the margin-top of its first
    child block, or no border, padding, inline content, height,
    min-height, or max-height to separate the margin-bottom of a block
    with the margin-bottom of its last child, then those margins collapse.
    The collapsed margin ends up outside the parent.

    In your example, the rule can be read as:

    • div#without does not have a border, its top margin (which is 0) is collapsed with the top margin of h1 (which is ~20px). The collapsed margin ends up outside the div. This means that these 20px do not add to the height of div.

    • div#with has a border, so the top margin of h1 (which is ~20px) is rendered inside the div, making it 20px taller than expected.

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

Sidebar

Related Questions

I have a HTML/XML document similar to the following. There can be one or
Consider the following code: $(document).ready(function() { $(body).append(<div class='outer'><span class='inner'>Click me</span></div>); $(html).click(function(event) { var targetClass
Only yesterday did I need to animate the border color of an HTML div
I need to search through an HTML document for two specific strings of text
I have a view that has two buttons(First and Second) and one hidden field.
I need to parse a html document that has been generated by saving a
With the following script I load a HTML document into a div-container and show
I have the following: QString html = ui->DetailsTextBrowser->document()->toHtml(); html = details.replace(#VERSION, 1.0); ui->DetailsTextBrowser->document()->setHtml(details); Unfortunately
I have the following at the top of my document: <html class=js lang=en xml:lang=en
I have the following code <xsl:result-document href=output1/output3/index.html format=html> <html> <head> <SCRIPT LANGUAGE=JavaScript> function getParams()

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.