I have a container with content. The container's width is fixed but its height is determined by its inner content.
Initially, the content of the container causes the container to be a particular height. I then want to shrink the inner elements content while maintaining the original height of the container.
In the snippet below, my goal is to maintain the initial height of the red box while still shrinking the font-size of the inner content.
function changeSize() {
document.querySelector('.box').classList.add('active');
}
.container {
border: 1px solid red;
width: 30%;
}
.box {
background: lime;
transition: font-size 1s linear;
}
.box.active {
font-size: 5px;
}
<div class="container">
<p class="box">This is some text which changes size and causes the container to change height.</p>
</div>
<button onclick="changeSize()">Change text size</button>
At the moment, the red-box shrinks with the inner content, whereas I want it to remain at its initial height.
I know I can give the container (ie: red box) a fixed height, but I want its height to be determined by the initial height of its inner contents.
Is there anyway to use CSS to maintain the initial height of the container while also being able to change the size of the child element? I tried adding a wrapper element to the content but wasn't too sure where to go from there.