Why does the element in the following example collapse on its own?
When you use display: flexin section, its children become flexible.
Flex flex, flex-grow, flex-shrink flex-basis, , .
flex-basis, , .
flex: 0 1 auto, , (0) , (1) flex- (auto) .
width flex-basis , , caret 3%, , , ( ), , , .
, , flex-shrink 0.
let t = 'Nothing is completely perfect.'
let c = 0
const e = document.getElementById('statement-container')
const i = setInterval(function(){
if (t[c] !== ' ') e.innerHTML += t[c]
else e.innerHTML += ' '
c++
if (c >= t.length) clearInterval(i)
}, 100)
* {
box-sizing : border-box;
}
body {
width : 100vw;
height : 100vh;
margin : 0;
}
section:first-child {
width : 40vw;
height : 100vh;
position : relative;
left : 30vw;
display : flex;
border : solid blue 1px;
}
#statement-container, #caret {
height : 15%;
position : relative;
top : calc(50% - 7.5%);
}
#statement-container {
font-family : beir-bold;
font-size : 15vmin;
color : red;
}
#caret {
flex-shrink : 0;
width : 5%;
border : solid green 5px;
background : orange;
}
<section>
<div id="statement-container"></div>
<div id="caret"></div>
</section>