It's possible to obtain the following masterpiece of recursive positioning of DIVs
by using the following code.
html, body { width: 100%; height: 100%; margin: 0; }
.outer {
width: 100%; height: 100%;
display: flex; flex-direction: column;
}
.inner {
margin: 10px;
border: 10px solid gray; border-radius: 10px;
display: flex; flex-direction: column;
flex: 1;
}
<div class="outer">
<div class="inner">
<div class="inner">
<div class="inner">
</div>
</div>
</div>
</div>
But something is odd about it. My attempts to display a border for the outer box fail (and box-sizing: border-box; doesn't help).
Can you modify this code to use styling for just html, body as well as one-box, where one-box would be used for both the outer DIV as well as an arbitrary nesting of inner DIVs?
Or does HTML5/CSS3 really require this baroque treatment of the base case when recursively nesting DIVs?
My attempt:
html, body {
width: 100%; height: 100%; margin: 0;
box-sizing: border-box;
}
.one-box-to-rule-them {
width: 100%; height: 100%;
display: flex;
flex-direction: column;
flex: 1;
margin: 10px;
border: 10px solid gray; border-radius: 10px;
box-sizing: border-box;
}
<div class="one-box-to-rule-them">
<div class="one-box-to-rule-them">
<div class="one-box-to-rule-them">
<div class="one-box-to-rule-them">
</div>
</div>
</div>
</div>
fails. Adding a border to the outer box using a unified box makes the boxes go out of bounds.
Explanation
A teacher who solves the problem I was having is valuable. A teacher who (also) points out how my knowledge was misleading me is invaluable. There are at this moment four (nice and correct) answers, but the insight into what I was misunderstanding is provided in a comment made by Temani Afif. Let me illustrate it with a diagram.
My mistake was thinking that when one changes box-sizing from its default content-box and specifies instead box-sizing: border-box;, the box calculation includes all four, content, padding, border, and margin. As its names implies, box-sizing: border-box; includes in the calculation the border-box. It does not include the margin.


