Unfortunately, this is not possible without knowing the boundaries of the width in advance. If you don’t know the width boundaries in advance or are dynamic, you're out of luck. 1
The area of the element containing the block is indeed defined as the filling edge of the element forming the containing block. This is explicitly stated in spec and by design; descendants usually should not overflow the border of their container, unless the container has overflow: visible and does not set BFC (and even then the effect is only visual, it does not affect the layout). Otherwise, the border is no longer the border.
As a rule, if you want to lay out elements in such a way that they interact along their border or outer edges, you do not want to lay them out as ancestors and descendants. At least you want them to be brothers and sisters 2 otherwise they should be completely unconnected.
This seems to me an oversight; the top: x% value should really depend on the box-sizing value of the parent ...
The purpose of box-sizing is to change the way the box size is calculated (i.e., add or add padding or borders to the dimensions specified by width and height ); while you can use it to change the size of the element’s padding field, the area of the containing block, if the element generates it, is still defined by this padding field.
1 This can be resolved using custom properties, but provided that you must assign the same custom property to both the parent border width and the child corresponding offsets, this is basically a different way of saying: “you must know the border width in advance "or at least have control over them.
2 Floats, for example, are highly predisposed to the borderline of the drawers, so that fields may appear to collapse in places where you usually did not expect this to happen.
source share