How to make font-size relative to the div element.

Hello, i started learning HTML/CSS recently and i can't understand how to make the text responsive. I want to make it like an image for example with width and height in %. But it doesn't work with font, i tryed with VH but when i resize the browser i have overflow issues. I saw videos about EM and REM but i don't see how this would help me. They are still fixed sizes like pixels. There is no way to make it relative to the size of a div? If you watch the screens i uploaded i used vh to the text and vh to the divs. When i resize the browser the text resizes to the screen size not the div element that is resizing too, and is creating me problems.
No description
No description
4 Replies
clevermissfox
clevermissfox14mo ago
Using vw and vh is not great as people can’t zoom. Use clamp, put in your min size and max size and they’ll calculate the resize rate. Also use the padding and margins in em so it resizes as the font-size grows or shrinks https://youtu.be/veEqYQlfNx8?si=SKBVEoVnF9j8sO2N https://utopia.fyi/clamp/calculator/
Kevin Powell
YouTube
The problems with viewport units
Conquering Responsive Layouts (free course): https://courses.kevinpowell.co/conquering-responsive-layouts Join the Discord: https://kevinpowell.co/discord Viewport units often feel like this cheat code that makes things so much easier when you first discover them, but they actually are problematic for a number of reasons, from creating horizon...
Utopia
Clamp calculator
Fluid responsive design
clevermissfox
clevermissfox14mo ago
Also if you don’t need to set the width of an element, don’t. Use the content and padding to make up the size. If you use padding in ems, the width will shrink or grow with the text And on inputs, use font: inherit; as it doesn’t by default.
DimitriUI
DimitriUIOP14mo ago
Thank you for the answer. I didn't even knew about the fact i can't zoom. I just realize that everything i learned in the past 2 weeks is bad. I always used vh thinking it will scale. Is still weird to me using em and rem. I found Kevin free Course for Responsive Layout that i am just starting now.
clevermissfox
clevermissfox14mo ago
Use clamp on your font sizes, it’s the best of both worlds! Conquering Responsive Layouts course? Good plan you’ll learn lots
Want results from more Discord servers?
Add your server