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 7991637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:20:52+00:00 2026-06-04T13:20:52+00:00

I have a Div, which dosn’t have fix height or width. the div will

  • 0

I have a Div, which dosn’t have fix height or width.
the div will contain some text, the length of string not fix. if the String is too long to fit in the div, the text will appear outside the div, what I need is to know how much maximum length of String the div can contain based on it’s width and height.

  • 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-06-04T13:20:54+00:00Added an answer on June 4, 2026 at 1:20 pm

    Unless you are using a fixed width font where all characters are the same width (which is unusual), there is no answer to your question. How many characters fit in a given width depends upon what the characters are as characters like a “W” are much wider than characters like an “i” in all variable width fonts.

    If you are using a fixed width font, then you need to measure how wide a character is in the font and font-size and font-style you’re using. You can then simply divide the width you have by the character width and determine how many characters will fit.

    It is possible to measure a fixed width font, by creating a div with no margin, padding or border, setting the style to position: absolute, setting the desired font-family and font-size on it and putting one character in the div. You can then fetch the width of the div by getting it’s offsetWidth.

    See http://jsfiddle.net/jfriend00/kHHU7/ for a simple example.

    Here’s a function that measure’s the width of a character in a fixed width font:

    function getCharWidth(fontFamily, fontSize) {
        var div = document.createElement("div");
        div.style.position = "absolute";
        div.style.visibility = "hidden";
        div.style.fontFamily = fontFamily;
        div.style.fontSize = fontSize;
        div.innerHTML = "S";
        document.body.appendChild(div);
        var width = div.offsetWidth;
        document.body.removeChild(div);
        return(width);
    }
    

    You can see it work here: http://jsfiddle.net/jfriend00/y4eZr/

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

Sidebar

Related Questions

I'm trying to create a div which will have fixed width and flexible height
I have a div which has some text, but according to different situations this
So I have a div which will contain 3 buttons and I want these
I have a div which will do some animation on click event.But I don't
I have a div which has width of say 200px. It does not show
I have a div which contains some text for the database: <div id=summary>Here is
I have one container div which contain 2 dynamic height (height haven't been set)
I have a div,which content some text content. <div id=con style=position:absolute;left:50px;top:50px;border:1px solid red;font-size:12px;> Text
I have a div which is width:500px; and height:170px; The div contains a jquery
I have a div which has 14 child divs with some content. Now what

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.