Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Have text shrink when needed to fit in div in CSS [duplicate]

Tags:

html

css

so I've got a bit of an issue. I have my header that looks like this: Header and it looks really poor on mobile as shown here: Mobile header

Would there be a good way to downscale text as needed to fit in the header? Preferably a CSS only solution.

I have a premade JSFiddle here with just the header for experimenting: https://jsfiddle.net/wgy1ohc3/1/

<div class="parallax-container header-parallax">
  <div class="container container-wide readable-text">
    <h1 class="white-text">Account Security</h1>
    <h4 class="white-text">Control active sessions and 2-Factor Authentication.</h4>
  </div>
  <div class="parallax"><img src="https://i.imgur.com/k45V80z.jpg?2"></div>
</div>

Any help whatsoever would be appreciated!

like image 234
tenten8401 Avatar asked Jan 18 '26 09:01

tenten8401


1 Answers

The vw or vh CSS measurement

For a fluid responsive text size adjustment, we can use the vw (viewer width) and vh (viewer height) CSS measurements.

They are widely supported and very useful.

Adding:

h1 {
    font-size: 10vw;
}
h4 {
    font-size: 4vw;
}

to your fiddle will give you a result close to what I believe you are seeking.

like image 151
Fred Gandt Avatar answered Jan 21 '26 03:01

Fred Gandt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!