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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:11:52+00:00 2026-05-20T01:11:52+00:00

So first a bit of meat to set the scene: HTML <div id=container> <div

  • 0

So first a bit of meat to set the scene:

HTML

<div id="container">
    <div id="inner">test</div>
</div>

CSS

#container {
    width:300px;
    height:150px;
    background-color:#d7ebff;
}

#inner {
    width:100%;
    height:100%;
    padding:5px;
    background-color:#4c0015;
    opacity:.3;
}

This will produce something that looks like this in all modern browsers:

CSS interior width test showing the inner box exceeding the container

Now I know this is the standards-compliant behavior (as I knew before, but reconfirmed in this post, and I also know that if I include this code in the inner CSS declaration:

box-sizing:border-box;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box

…it will adopt the “border-box” model and get the behavior that seems more intuitive to me, but I just found myself trying to logically justify the reasoning behind why this is the way it is and I was unable to do it.

It seems (on the surface of things) more logical to me for the inner box to always fill the container to exactly 100% of the container’s width, regardless of the padding or border of the inner box. I run into this problem all the time when I’m trying to set the width of a textarea to 100% that has a border or something like a 4px interior padding…the textarea will always overflow the container.

So my question is…what is the logic behind setting the default behavior to ignore the border and padding of an element when setting its width?

  • 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-20T01:11:52+00:00Added an answer on May 20, 2026 at 1:11 am

    The reason CSS uses the box model as:

    +---------------------
    |       Margin
    | +-------------------
    | |     Border
    | | +-----------------
    | | |   Padding
    | | | +---------------
    | | | | Width x Height
    

    Is because CSS is a document styling language. It was (originally) designed with research papers and other formal documents in mind, not as a way to make pretty graphics. As such, the model revolves around the contents, not the container.

    CSS isn’t a programming language, it’s a styling language. It doesn’t explicitly tell the document how it should be displayed, it suggests some guidelines the browser should follow. All of these can be overwritten and modified by an actual programming language: JavaScript.

    Going back to the content-model idea, consider the following CSS:

    p
    {
      background-color: #EEE;
      border: 1px solid #CCC;
      color: #000;
      margin: 10px;
      padding: 9px;
      width: 400px;
    }
    

    height isn’t specified, because the content defines the height, it may be long, it may be short, but it’s unknown, and unimportant. The width is set to 400px because that’s how wide the content (text) should be.

    The padding is just a means of extending the background color so that the text can be nicely legible away from the edges, just like how you leave space when writing/printing on a sheet of paper.

    The border is a means of surrounding some content to differentiate it from the other backgrounds, or to provide a border (go figure) between various elements.

    The margin tells the paragraph to leave some space between edges, and with margin-collapsing, each group will remain evenly spaced without having to specify a different margin for the first or last element.

    To maintain fluidity, width defaults to auto, which means the width will be as wide as possible:

    1. without squishing the content unreasonably
    2. without the padding extending beyond its container

    Of course, in edge cases, the padding will extend beyond its container because the content might get squished. It’s all about the content.

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

Sidebar

Related Questions

i need to strip ../something/ from a url eg. strip ../first/ from ../first/bit/of/the/url.html where
Below I have 2 css codes for a div, please note that the first
This first bit works: $my_id = 617; $post_id_7 = get_post($my_id); $title = $post_id_7->post_excerpt; echo
I understand that the first bit is the sign and that the next 8
I'm doing the first bit of web-page development I've done in years, in VS2008,
I'm working on my first object oriented bit of python and I have the
First, a bit of context: web.xml: I match all /app/* requests to my dispatcher:
first time poster and TDD adopter. :-) I'll be a bit verbose so please
I'm doing a bit of Powershell scripting ( for the first time ) to
This will be my first iOS app with any bit of complexity. I'd like

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.