Artifacts Gallery Guilds Search Wiki Login Register

Welcome, Guest. Please login or register. - Thinking of joining?
June 16, 2026 - @144.58 (what is this?)
Activity rating: Two Stars Posts & Arts: 16/1k.beats Random | Recent Posts | Guild Recents
News: :4u: ~~~~~~~~~~~  :4u: Guild Events: Happy Pride Month Fibre Artists!

+  MelonLand Forum
|-+  Life & The Web
| |-+  ✁ ∙ Web Crafting
| | |-+  ☔︎ ∙ I need Help!
| | | |-+  Scale font-size to always fit within container?


« previous next »
Pages: [1] Print Embed
Author Topic: Scale font-size to always fit within container?  (Read 8 times)
voidpain
Newbie ⚓︎
*
View Profile WWW


hello it's me, the Bible! Ive become a human boy!
⛺︎ My Room

Guild Memberships:
Artifacts:
Joined 2026!
« on: Today at @5.51 » Embed

hi! 1rst post here and im asking for help.. typical.

The connundrum: i want to have text within a title card that will change on every page. I figured sorting out a way to have the text scale in size to always fit within the container would save me from having to manually set the font-size on every page.

You can kinda preview what ive already got set up here; https://voidpain.neocities.org/src. the exasperated "broooooooo" would ideally fit most of the horizontal space marked by the bg img behind it. Even when O's are removed or added, the text would shrink or grow accordingly to compensate and still take up most of the space provided.

Ive found some solutions online that demonstrate what i mean; namely this demo of textFit.js (https://codepen.io/chriscoyier/pen/GGQKJE) which ive tried implementing in my code with no luck.

Having failed to get textFit to work, i also found this snippet :

Code
const input = document.querySelector('input');
const output = document.querySelector('.output');
const outputContainer = document.querySelector('.container');

function resize_to_fit() {
  let fontSize = window.getComputedStyle(output).fontSize;
  output.style.fontSize = (parseFloat(fontSize) - 1) + 'px';
  
  if(output.clientHeight >= outputContainer.clientHeight){
    resize_to_fit();
  }
}

function processInput() { 
  output.innerHTML =this.value;
  output.style.fontSize = '100px'; // Default font size
  resize_to_fit();
}

input.addEventListener('input', processInput);

It also resizes the text the way i imagine, but relies on user input to get the text in the first place and i dont want that lol. I dont know enough about javascript to rewrite the code to resize the inner html without all those bells and whistles so any help with that, or pointers as to any other ways i could achieve this would be appreciated.

Thanks melonland :]!
Logged

https://file.garden/aQesLHeiMyzNe4NG/Misc/Gifs/IMG_7639.gif
Pages: [1] Print Embed 
« previous next »
 

Melonking.Net © Always and ever was! SMF 2.0.19 | SMF © 2021 | Privacy Notice | Send Feedback | Supporters ♥ Forum Guide | Rules | RSS | WAP | Mobile


MelonLand Badges and Other Melon Sites!

MelonLand Project! Visit the MelonLand Forum! Support the Forum
Visit Melonking.Net! Visit the Gif Gallery! Pixel Sea TamaNOTchi
MelonLand @000

Minecraft: Online
Join: craft.melonking.net