Problems encountered in flex layout about whether border exists or not

HTML

<div class="box">
    <div class="div1" style="background:red;"></div>
    <div class="div2" style="background:blue;"></div>
    <div class="div3" style="background:peru;"></div>
</div>

CSS

html,body,.box{
    height: 100%;
    width: 100%;
    margin:0;
    padding: 0;
}
.box{
    display:flex;
    flex-wrap: wrap;
}
.div1,.div2{
    width:50%;
    height: 80%;
}
.div3{
    flex:1;
    height:20%;
    width: 100%;
    /* border:1px solid -sharp000; */
}

.div3 has border to achieve the desired layout effect. Without this attribute, the width of .div3 will become zero.

Dec.31,2021

.div3{
    flex:1; //
    height:20%;
    width: 100%;
}

this involves the question of attribute priority. When the width of child elements under the flex:1,flex layout container is explicitly set to take the value of flex, width will not work. Border:1px is equivalent to the width of 1px, and the first two account for 50%, and the third one will be squeezed down. When there is no such attribute, flex:1 will occupy all the remaining 0. When flex:1 is removed, The width attribute takes effect, and line breaks take up all of it. Personal guess

Menu