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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:14:32+00:00 2026-06-14T09:14:32+00:00

I need to truncate strings in a side menu to make them fit into

  • 0

I need to truncate strings in a side menu to make them fit into a div without a linebreak. The divs have a fixed width. I’m looking for a library to do that for me.
If a string is too long to fit into the div, it should be truncated like this:

<div>This string is too long</div> ==> <div>This string is...ong</div>

As you can see, the string is not only truncated by an ellipsis but the last three letters are also visible. This is meant to increase readability. The truncation should not care about spaces.

Does anyone know of a library that includes such functionality? We’re mainly using jQuery throughout the project.

Thanks in advance!

  • 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-14T09:14:34+00:00Added an answer on June 14, 2026 at 9:14 am

    I don’t know of a library per se that does that, but using an HTML5 Canvas and Canvas text metrics, you could determine whether the string would fit in, and if not, how much you’d have to cut it out.

    var canvas = document.createElement('canvas');
    var context = canvas.getContext('2d');
    context.font = '12pt Arial';
    var metrics = context.measureText('measure me!');
    var width=metrics.width;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an apparently simple regex query for pipes - I need to truncate
I need to write some client-side javascript for a webpage that will truncate the
I need to truncate string and rewrite it back to array I have got
I have an array and I need to truncate this array down to only
I have some strings in my PHP code that need to be truncated if
I need to truncate a comma at the end of a string, sort of
I need to truncate the amount of decimal places of my double value for
I need a rewrite in how the modifier 'truncate' is called, because it is
Need some regular expressions help. So far I have my code working to allow
Need some help... I have jasperserver 4.1 installed on my ubuntu. It runs via

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.