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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:43:20+00:00 2026-05-25T03:43:20+00:00

Lets say we have a <div style=width:100px;>This text is too long to fit</div> The

  • 0

Lets say we have a <div style="width:100px;">This text is too long to fit</div>

The text in the div is dynamic. And I’d like to force the text to fit in width and not break.
So i need some kind of functionality to test if the text is going to fit, and if it is not, then i’d like to display the portion of the text that will actually fit. And append ...to the end.

Result for a too long text should be something like this: "This text is..."

Is there some standard way of doing what i want? Either by javascript, jquery, jsp or java?

Thanks!

Edit:
Thanks for your quick and many answers! I was doing this in java by guessing how many characters would fit. It seemed like a less than optimal solution, so thats why i came here.

The css solution is perfect for me. Its not that big of a deal that it doesnt work for firefox, since my clients all use ie anyway. 🙂

  • 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-25T03:43:21+00:00Added an answer on May 25, 2026 at 3:43 am

    you could do it with css3 using text-overflow:ellipsis http://www.css3.com/css-text-overflow/

    or if you insist on using the js way, you can wrap the text-node inside your div and then compare the width of the wrap with the with of the parent.

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

Sidebar

Related Questions

You know what I mean? Like let's say we have: <div style=width:100px;font-size:10px>Some Text</div> But
Let's say I have an html snippet like this: <div style=width:300px;> <label for=MyInput>label text</label>
Lets say I have some markup like this: <html> <head> <style type=text/css> #container {
I have a setup lets say like follows: <div id=nav> <div id=innernav> //With dynamic
So, lets say that we have this structure: <div id='allTempLinkHolder'> <div class='tempLink'>Value</div> <div class='tempLink'>Value
Let's say we have a box with some short paragraphs: <div style=overflow:hidden> <p>Some text</p>
Let's say I have a list like this: <ul class=list> <li><span class=pos><div class=txt_pos>1</div></li> <li><span
Let's say this is my HTML: <ul> <li><div style=width: 10em;>Hello</div><div class=ble></div></li> </ul> I want
Lets say I have this code: <div class=user> <img class=profilepic src=someimage.jps> <div class=cleaner></div> [
Let's say you have the following HTML: <html> <div style=text-align: center;> <img src=http://www.ps.uci.edu/~tomba/ants/sugar.jpg width=50

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.