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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:30:24+00:00 2026-05-16T10:30:24+00:00

There may be a simple fix for this, but it has troubled me for

  • 0

There may be a simple fix for this, but it has troubled me for ages now…

Let me explain the situation. I have a div with the ID ‘container’ that holds all the contents in the page (including header and footer also) that will keep everything inline and I can do just 1 simple ‘margin:0 auto;’ instead of multiples. So lets say that I have the width of #container set to 80%. Now if I put another div inside with the same width (80%) and give it the ID of ‘header’ with 10px of padding all around, the layout would “break” (so to speak) because the page adds the padding amount onto the width. So, how can I make it stay in-bounds without using methods such as a lower percentage for the #header div? Basically, I want to make it fluid.

Here is some example code to give you an idea of what I am talking about…

CSS

#container {
    position:relative;
    width:80%;
    height:auto;
}
#header {
    position:relative;
    width:80%;
    height:50px;
    padding:10px;
}

HTML

<div id="container">
    <div id="header">Header contents</div>
</div>

Can anyone help me out with this issue that has been bugging me forever?

  • 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-16T10:30:25+00:00Added an answer on May 16, 2026 at 10:30 am

    If you want the #header to be the same width as your container, with 10px of padding, you can leave out its width declaration. That will cause it to implicitly take up its entire parent’s width (since a div is by default a block level element).

    Then, since you haven’t defined a width on it, the 10px of padding will be properly applied inside the element, rather than adding to its width:

    #container {
        position: relative;
        width: 80%;
    }
    
    #header {
        position: relative;
        height: 50px;
        padding: 10px;
    }
    

    You can see it in action here.

    The key when using percentage widths and pixel padding/margins is not to define them on the same element (if you want to accurately control the size). Apply the percentage width to the parent and then the pixel padding/margin to a display: block child with no width set.


    Update

    Another option for dealing with this is to use the box-sizing CSS rule:

    #container { 
        -webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
        -moz-box-sizing: border-box;    /* Firefox, other Gecko */
        box-sizing: border-box;         /* Opera/IE 8+ */
    
        /* Since this element now uses border-box sizing, the 10px of horizontal
           padding will be drawn inside the 80% width */
        width: 80%;
        padding: 0 10px;
    }
    

    Here’s a post talking about how box-sizing works.

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

Sidebar

Related Questions

This may be a simple fix (well, it probably is) but for some reason
This may not be possible for the carousel but is there a way to
This may fall under you can't, and there's no reason to anyway, but I'm
I'm sure this is a simple issue, but I have noticed that when I
I have the following String Sample however in some occurences there may be one
I may get some heat for this question because there are a lot out
This may be a bit obscure, but I'm developing a viewer app that chunks
This may seem a common question but I googled to find the right answer
I am sorry if this is a simple fix (I'm sure it probably is)
I think this should be a simple fix, or perhaps I am going at

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.