Why does the element in the following example collapse in on itself?
Even though the element is set to box-sizing: border-box
, its border will remain, yet the element loses all of its width as soon as it breaches the perimeter of its parent.
What is going on?
let t = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus at velit commodo, facilisis ex vitae, viverra tellus.'
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 {
z-index : 98;
font-family : beir-bold;
font-size : 6.5vmin;
color : red;
}
#caret {
z-index : 99;
width : 10%;
border : solid green 5px;
background : orange;
}
<body>
<section>
<div id="statement-container"></div>
<div id="caret"></div>
</section>
</body>