When the container is not set to width:100%, the box-sizing:border-box is not working.
Example:
header {
padding: 50px;
background-color: purple;
box-sizing: border-box;
height: 50px;
}
main {
padding: 10px;
background-color: blue;
width: 50px;
height: 60px;
}
<main>
<header>header</header>
</main>
In this example, the "header" exceeds its container "main" when i increase the padding. Why is the border-box not working here? I thought it was supposed to count the padding and borders with the width of the element. Why is it exceeding the container then?
Another case is when i set the width to 100%, and then set the padding to over 700px, then it starts to exceeds the same way.
html {
padding: 10px;
background-color: orange;
}
body {
background-color: yellow;
padding: 10px;
}
header {
padding: 800px;
background-color: purple;
box-sizing: border-box;
height: 50px;
width: 100%;
}
main {
padding: 10px;
background-color: blue;
}
<body>
<main>
<header>header</header>
</main>
</body>
Up until padding:700px, the "header" was container within the width of the container. Once the padding is increased above 700px, it starts to exceed the width of the container.
So, first of all, why? Why is it working up until 700px, and why is it not working for the height? and why is it not working at all when the width is set to a number lower than 100%?