Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 886421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:03:55+00:00 2026-05-15T13:03:55+00:00

i have a blue container that is the canvas for my text. what i’m

  • 0

i have a blue container that is the canvas for my text. what i’m trying to do is resize the font so that the entire text fills as much of the blue container as it can.

i have access to the height of the text content, which is both paragraphs and the line in between them. also, i have the height of the blue container, the height of each line, the number of lines and the number of words.

i tried using the height of the line, based on a default font size, with the amount of lines to determine how much i need to increase the font so it would fill the blue container. however, doing so also changes the amount of lines, ruining my chances for success while making my head swim.

what formula should i use so the font size fills the blue container?

here are my numbers:

Content height:  342.46
Content/Container Width:  400
Font Size:  11
Line Height:  11 * 1.2 //120% of the font size gives the line height
Number of Lines:  24
Number of Words:  2055

also, it’s possible for the text content to be long and to extend well past the container, so ideally a formula (or suggestions) for both an increase or reduction of the font size is what i’m trying to achieve.

alt text http://www.freeimagehosting.net/uploads/c1a4f77c5f.jpg

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T13:03:56+00:00Added an answer on May 15, 2026 at 1:03 pm

    In TeX typesetting system this problem is usually solved using a simple bisection algorithm (presented f.e. by Knuth in The TeXbook), here in a pseudo-python:

    def findsize:
        maxsize=100pt
        minsize=8pt
        epsilon=0.5pt
        while (maxsize-minsize>epsilon):
            triedsize=(maxsize+minsize)/2
            setfontsize(triedsize)
            if boxisoverfull():
                maxsize=triedsize
            else:
                minsize=triedsize
        return minsize
    

    Note that you probably can’t do this without experimenting with every size, as every browser might typeset your text in different way, making different interword, interletter spacing; by having a minimum font size set by user (I’ve seen lots of webpages displaying improperly because of this one), by using ligatures (probably not now, but in future it is possible).

    The problem here is that the webbrowser will probably redraw every try, so this might be slow. You can overcome this by making the box disappear (f.e. display:none) for the time of computation. I remember I did that once and it worked even in IE6.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Textbox with blue Background and white Foreground . When entering a text
I have two blocks in HTML5 canvas. Blue Block ie fixed in the canvas
I have a really stuburn layout, that I just can not resolve .. -
You can see the way its suppose to work by visiting: link text That
I have a web page with one big container for the entire page. Inside
I have an image that I am using as my background and am trying
I have one image and text that goes along with it to the side
I have Image in ItemTemplate that will be changing according to Username (ie lblPostedBy.Text).
I currently have a simple setup: a centered container div that is 90% width
I have written a program that uses widgets as container (for other widgets). Because

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.