Why does the background color scale down more than the font?

Why does this happen and what to do about it? I have a normal div with lots of text and a background color and a font size of 2rem. When I start reducing the width, after some point the the text and background-color start to scale down disproportionately. Any explanation would be appreciated. Here's a code pen link, but doing this locally on the machine would reproduce the issue better. https://codepen.io/prashant6299/pen/JjQGWpK
8 Replies
ἔρως
ἔρως6mo ago
that's because the text is too big for the viewport
Jochem
Jochem6mo ago
The background color will scale the way you tell it, but the font will eventually overflow from its container when you try to shrink it to a point where the target size of the container is smaller than the width of any particular word
ἔρως
ἔρως6mo ago
all you need to do is ... reduce the font size or try to make wordwrap work
EthanXDiaz
EthanXDiazOP6mo ago
Thanks for the response, that's insightful, although i couldn't find this documented anywhere, is there a source? and also what is usually done in this case? Thanks for the help. What do you mean by making wordwrap work?
ἔρως
ἔρως6mo ago
exactly that i don't know how to explain it any better
Jochem
Jochem6mo ago
either a media query, or using a font size that's defined with clamp and using vw as one of the components (and always, always, always having a rem component in the middle term of the clamp)
ἔρως
ἔρως6mo ago
that is a better solution, yes
EthanXDiaz
EthanXDiazOP6mo ago
Thanks a lot guys.
Want results from more Discord servers?
Add your server