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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T13:52:16+00:00 2026-05-10T13:52:16+00:00

In my (PHP) web app, I have a part of my site that keeps

  • 0

In my (PHP) web app, I have a part of my site that keeps a history of recent searches. The most recent queries get shown in a side box. If the query text is too long, I truncate it and show ellipses. Eg: ‘My very long query is…’

Currently, I truncate after a certain number of characters. Since the font is not monotype, a query of all I’s is more narrow than a query of all W’s. I’d like them to all be about the same width prior to the ellipses. Is there a way to get the approximate width of the resulting string so that the ellipses for any given string will occur in about the same number of pixels from the beginning? Does CSS have a way? Does PHP? Would this be better handled by JavaScript?

  • 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-10T13:52:16+00:00Added an answer on May 10, 2026 at 1:52 pm

    Here’s another take on it and you don’t have to live without the ellipsis!

    <html> <head>  <style> div.sidebox {     width: 25%; }  div.sidebox div.qrytxt {     height: 1em;     line-height: 1em;     overflow: hidden; }  div.sidebox div.qrytxt span.ellipsis {     float: right; } </style>   </head>  <body>  <div class='sidebox'>     <div class='qrytxt'>         <span class='ellipsis'>&hellip;</span>         Some long text which will arbitrarily be cut off at whatever word fits best but will have an ellipsis at the end.     </div>     <div class='qrytxt'>         <span class='ellipsis'>&hellip;</span>         Some more long text which will arbitrarily be cut off at whatever word fits best but will have an ellipsis at the end.     </div>     <div class='qrytxt'>         <span class='ellipsis'>&hellip;</span>         Short text. Fail!     </div> </body>  </html> 

    There is one flaw with this, if the text is short enough to be fully displayed, the ellipses will still be displayed as well.

    [EDIT: 6/26/2009]

    At the suggestion of Power-Coder I have revised this a little. There are really only two changes, the addition of the doctype (see notes below) and the addition of the display: inline-block attribute on the .qrytxt DIV. Here is what it looks like now…

    <!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01//EN' 'http://www.w3.org/TR/html4/strict.dtd'> <html> <head>     <style>         div.sidebox          {             width: 25%;         }          div.sidebox div.qrytxt         {             height: 1em;             line-height: 1em;             overflow: hidden;             display: inline-block;         }          div.sidebox div.qrytxt span.ellipsis         {             float: right;         } </style> </head>  <body>     <div class='sidebox'>         <div class='qrytxt'>             <span class='ellipsis'>&hellip;</span>             Some long text which will arbitrarily be cut off at whatever word fits best but will have an ellipsis at the end.         </div>          <div class='qrytxt'>             <span class='ellipsis'>&hellip;</span>             Some more long text which will arbitrarily be cut off at whatever word fits best but will have an ellipsis at the end.         </div>          <div class='qrytxt'>             <span class='ellipsis'>&hellip;</span>             Short text. FTW         </div>     </div> </body> </html> 

    Notes:

    • Viewed in IE 8.0, Opera 9, FF 3

    • A doctype is required for IE to get the display: inline-block to work correctly.

    • If the .qrytxt DIV’s overflow occurs on a long word, there is going to be a wide gap between the ellipsis and the last visible word. You can see this by viewing the example and resizing your browser width in small increments. (this probably existed in the original example as well, I just may have not noticed it then)

    So again, an imperfect CSS-only solution. Javascript may be the only thing that can get the effect perfect.

    [EDIT: 6/27/2009]

    Here is another alternative which uses browser specific extensions.

    <!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01//EN' 'http://www.w3.org/TR/html4/strict.dtd'>  <html> <head>     <style>         div.sidebox          {             width: 26%;         }          div.sidebox div.qrytxt         {             height: 1em;             line-height: 1em;             overflow: hidden;             text-overflow:ellipsis;             -o-text-overflow:ellipsis;             -ms-text-overflow:ellipsis;             -moz-binding:url(ellipsis-xbl.xml#ellipsis);             white-space:nowrap;         }     </style> </head>  <body>     <div class='sidebox'>         <div class='qrytxt'>             Some long text which will arbitrarily be cut off at whatever word fits best but will have an ellipsis at the end.         </div>          <div class='qrytxt'>             Some more long text which will arbitrarily be cut off at whatever word fits best but will have an ellipsis at the end.         </div>          <div class='qrytxt'>             Short text. FTW         </div>     </div> </body> </html> 

    Note that in order for the above example to work, you must create the xml file referenced by the -moz-binding rule, ellipsis-xbl.xml. It’s should contain the following xml:

    <?xml version='1.0' encoding='UTF-8'?>   <bindings xmlns='http://www.mozilla.org/xbl' xmlns:xbl='http://www.mozilla.org/xbl' xmlns:xul='http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul'>     <binding id='ellipsis'>       <content>         <xul:window>           <xul:description crop='end' xbl:inherits='value=xbl:text'><children/></xul:description>         </xul:window>       </content>     </binding>   </bindings> 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 62k
  • Answers 62k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Assuming that you're unable to update/insert into the existing table,… May 11, 2026 at 10:10 am
  • added an answer In Visual studio 2005 every reference you add adds a… May 11, 2026 at 10:10 am
  • added an answer I bet this will work if you use a file://… May 11, 2026 at 10:10 am

Related Questions

In my (PHP) web app, I have a part of my site that keeps
How can I measure number of lines of code in my PHP web development
On various pages throughout my PHP web site and in various nested directories I
I have a web page x.php (in a password protected area of my web
I just want to send SMS from my web application in PHP. Can anyone
How can I set the cookies in my PHP apps as HttpOnly cookies ?
I have several static factory patterns in my PHP library. However, memory footprint is
I am using HTML Purifier in my PHP project and am having trouble getting
I have a .ini file with sensitive information in my php wab app. I
Why should I use <?php instead of <? in my php script?

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.