I recently discovered this problem.
Check for demo on jsfiddle
As for me, the outline behaves wrong, doesn’t it? Shouldn’t the box model of the .outside
element include its borders, so that the absolute
positioned child element outlines those borders aswell?
Is this a known problem? Is this really correct behavior? If so, could someone explain to me why it is?
What I expected to have as result
Please do not comment on how to solve the problem. But please explain why the problem occurs.
Thanks in advance :)
Regards phlips
No they won't. Even if we consider that it's the only CSS applied to your document, the example B will also target pseudo element to make them inherit the box-sizing and if we follow the parent-child structure they will logically get box-sizing:border-box since html is having box-sizing:border-box .
CSS border-box is the most popular choice for setting box-sizing . It guarantees that the content box shrinks to make space for the padding and borders. Therefore, if you set your element width to 200 pixels, border-box makes sure that the content, padding, and borders fit in this number.
The box-sizing property allows us to include the padding and border in an element's total width and height. If you set box-sizing: border-box; on an element, padding and border are included in the width and height: Both divs are the same size now!
Note :- when using box-sizing : content-box; the content size remain same while border-box size grows as padding and border grow.
Just box-sizing: border-box
is not enough, you need to inherit width and height from parent:
.inside {
position: absolute;
outline: #00f solid 2px;
width: inherit;
height: inherit;
}
Check here https://jsfiddle.net/2mytb43a/3/
In this case when using position: absolute ..
.. the containing block is formed by the padding edge of the ancestor.
See CSS Specifications - 10.1 Definition of "containing block"
For whatever reason..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With