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

  • Home
  • SEARCH
  • 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 52467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T16:54:41+00:00 2026-05-10T16:54:41+00:00

I want to resize the font of a SPAN element’s style until it the

  • 0

I want to resize the font of a SPAN element’s style until it the SPAN’s text is 7.5 inches wide when printed out on paper, but JavaScript only reports the SPAN’s clientWidth property in pixels.

<span id='test'>123456</span> 

And then:

#test {   font-size:1.2in; /* adjust this for yourself until printout measures 7.5in wide */ } 

And then:

console.log(document.getElementById('test').clientWidth); 

I’ve determined experimentally on one machine that it uses approximately 90 DPI as a conversion factor, because the above code logs approximately 675, at least under Firefox 3.

This number is not necessarily the same under different browser, printer, screen, etc. configurations.

So, how do I find the DPI the browser is using? What can I call to get back ’90’ on my system?

  • 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. 2026-05-10T16:54:42+00:00Added an answer on May 10, 2026 at 4:54 pm

    I think this does what you want. But I agree with the other posters, HTML isn’t really suited for this sort of thing. Anyway, hope you find this useful.

    <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'> <html xmlns='http://www.w3.org/1999/xhtml'> <head> <meta http-equiv='Content-Type' content='text/html; charset=utf-8' /> <title>Untitled Document</title> <style type='text/css'> #container {width: 7in; border: solid 1px red;} #span {display: table-cell; width: 1px; border: solid 1px blue; font-size: 12px;} </style> <script language='javascript' type='text/javascript'> function resizeText() {   var container = document.getElementById('container');     var span = document.getElementById('span');      var containerWidth = container.clientWidth;   var spanWidth = span.clientWidth;      var nAttempts = 900;     var i=1;     var font_size = 12;      while ( spanWidth < containerWidth && i < nAttempts ) {       span.style.fontSize = font_size+'px';          spanWidth = span.clientWidth;          font_size++;       i++;     }        } </script> </head>  <body> <div id='container'> <span id='span'>test</span> </div> <a href='javascript:resizeText();'>resize text</a> </body> </html> 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to resize the font of all elements of a page like user
I want to resize the dialog dynamically just before I open it, but this
I have an image . I want to resize it using PIL, but it
I want to resize menu bar because the length and font size looks too
I want to resize images that are bigger than the window, but I keep
How can I resize a box or a font-size on window resize? But the
I want to resize the font of my UITableView cells. If they contain too
I have tspan element with some text in it. I specified some font-size for
I want to resize an image on the sd card and send it to
I want to resize cell's height according to the label's height and label's height

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.