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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:16:38+00:00 2026-05-13T13:16:38+00:00

There is an inner div of fixed width and variable height contained by an

  • 0

There is an inner div of fixed width and variable height contained by an outer div. The inner div should have a 5px margin on all 4 sides between it and the outer div.

How can this be achieved if the height of inner div is not specified?

With the height of the inner div specified this is very simple. But the inner div is a content container for a masterpage. The content going into this div will have a different height for each page that uses the master page.

If the inner divs height is not set, the bottom margin (between where the inner div ends and the outer div ends) is always 2-3px too long. i.e. 5 5 5 8 This happens across browser types.

Here is the CSS:

#contentframe
{
    position: relative;
    width: 1010px;
    left: 0px;
    top: 0px;
    margin: 0px;
    padding-top:5px;
    padding-bottom:5px;
    padding-left: 14px;
}
#content
{
    position: relative;
    left: 0px;
    top: 0px;
    width: 980px;
    margin: 0px;
    padding: 0px;
    background-color: #cccccc;

}

*** Note: Setting margin-bottom of #content to 5px does not work.

HTML:

    <div id="contentframe">
        <div id="content">
            variable height content will go in here
        </div>
    </div>

This should be dead simple. Set: Outer divs padding to 5px and that’s it. But that only works if inner divs height is specified. Otherwise there is an annoyingly “high” bottom margin.

EDIT: Full Source

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css"> 
body
{
    -x-system-font: none;
    background-color: #A2A2A2;
    margin-top: 0px;
    margin-bottom: 35px;
    padding: 0px;
}
#centeredframe
{
    width: 1010px;
    margin-left: auto;
    margin-right: auto;
    margin-top: 0px;
    padding: 0px;
}

#contentframe
{
    position: relative;
    width: 1010px;
    left: 0px;
    top: 0px;
    margin: 0px;
    padding-top: 5px;
    padding-bottom: 5px;
    padding-left: 5px;
    background-color: #ffffff;
}

#content
{
    position: relative;
    left: 0px;
    top: 0px;
    width: 1005px;
    margin: 0px;
    padding: 0px;
    height:300px;
    color: #ffffff;
    background-color: #000000;
}

</style>
</head>
<body>
    <div id="centeredframe">
        <div id="contentframe">
            <div id="content">
                <p>hgjghjghjghjg<p>
                <p>hgjghjghjghjg<p>
                <p>hgjghjghjghjg<p>
                <p>hgjghjghjghjg<p>
            </div>
        </div>
    </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-05-13T13:16:38+00:00Added an answer on May 13, 2026 at 1:16 pm

    This should work on IE7/8 and other non-IE browsers.

    The extra ‘padding/margin’ to the top and/or bottom is introduced by the <p> elements. This is due to the uncollapsing margin for empty-content/padding/border areas (in this case, the contentFrame). Refer to the W3C Box Model on collapsing margins.

    There are a few ways around it, one of which is to introduce a thin (1px) border which blends into the background of the DIV and then compensating with the width/height. Below is another hack by manipulating the margin/padding of the <P> element within the content DIV.

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <style type="text/css"> 
    body
    {
        -x-system-font: none;
        background-color: #A2A2A2;
        margin: 0;
        margin-bottom: 35px;
        padding: 0px;
    }
    #centeredframe
    {
        width: 1010px;
        margin: 0 auto; /* merged */
        padding: 0;
    }
    
    #contentframe
    {
        width: 1000px;
        margin: 0;
        padding: 5px;
        background-color: #ffffff;
    }
    #content
    {
        padding: 0;
        color: #ffffff;
        background-color: #000000;
        height: auto;
        min-height: 300px;
    }
    #content p
    {
        margin: 0px; /* removed the default margin of p element*/
        padding: 16px 0; /* replaced with padding to have background*/
    }
    </style>
    </head>
    <body>
        <div id="centeredframe">
            <div id="contentframe">
                <div id="content">
                    <p>hgjghjghjghjg</p>
                    <p>hgjghjghjghjg</p>
                    <p>hgjghjghjghjg</p>
                    <p>hgjghjghjghjg</p>
                </div>
            </div>
        </div>
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There is a div that has inner content, a div with a border that's
Is there any efficiency difference in an explicit vs implicit inner join? For example:
EDIT: For the inner queries, there could be more than one match per inner
There are numerous Agile software development methods. Which ones have you used in practice
I practiced to center a div without a width and found a solution that
I have used two div tags in my blog to wrap programming codes. The
I have a CSS layout that simulates a fixed-frame page, with a header and
There is a conversion process that is needed when migrating Visual Studio 2005 web
There are two weird operators in C#: the true operator the false operator If
There are two popular closure styles in javascript. The first I call anonymous constructor

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.