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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T23:50:51+00:00 2026-05-11T23:50:51+00:00

Is there any good way of truncating text with plain HTML and CSS, so

  • 0

Is there any good way of truncating text with plain HTML and CSS, so that dynamic content can fit in a fixed-width-and-height layout?

I’ve been truncating server-side by logical width (i.e. a blindly-guessed number of characters), but since a ‘w’ is wider than an ‘i’ this tends to be suboptimal, and also requires me to re-guess (and keep tweaking) the number of characters for every fixed width. Ideally the truncation would happen in the browser, which knows the physical width of the rendered text.

I’ve found that IE has a text-overflow: ellipsis property that does exactly what I want, but I need this to be cross-browser. This property seems to be (somewhat?) standard but isn’t supported by Firefox. I’ve found various workarounds based on overflow: hidden, but they either don’t display an ellipsis (I want the user to know the content was truncated), or display it all the time (even if the content wasn’t truncated).

Does anyone have a good way of fitting dynamic text in a fixed layout, or is server-side truncation by logical width as good as I’m going to get for now?

  • 1 1 Answer
  • 1 View
  • 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-11T23:50:52+00:00Added an answer on May 11, 2026 at 11:50 pm

    Update: text-overflow: ellipsis is now supported as of Firefox 7 (released September 27th 2011). Yay! My original answer follows as a historical record.

    Justin Maxwell has cross browser CSS solution. It does come with the downside however of not allowing the text to be selected in Firefox. Check out his guest post on Matt Snider’s blog for the full details on how this works.

    Note this technique also prevents updating the content of the node in JavaScript using the innerHTML property in Firefox. See the end of this post for a workaround.

    CSS

    .ellipsis {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        -o-text-overflow: ellipsis;
        -moz-binding: url('assets/xml/ellipsis.xml#ellipsis');
    }
    

    ellipsis.xml file contents

    <?xml version="1.0"?>
    <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>
    

    Updating node content

    To update the content of a node in a way that works in Firefox use the following:

    var replaceEllipsis(node, content) {
        node.innerHTML = content;
        // use your favorite framework to detect the gecko browser
        if (YAHOO.env.ua.gecko) {
            var pnode = node.parentNode,
                newNode = node.cloneNode(true);
    
            pnode.replaceChild(newNode, node);
        }
    };
    

    See Matt Snider’s post for an explanation of how this works.

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

Sidebar

Related Questions

is there any good way to remove everything from a string except the content
Is there any good way to deal with the class renaming refactor from Resharper
Is there any good way to convert strings like xlSum, xlAverage, and xlCount into
Is there any good way to unit test destructors? Like say I have a
Is there any good way convert a binary (base 2) strings to integers in
Regardless of the layout being used for the tiles, is there any good way
When using linq and you have c.Sort() Is there any good inline way of
Are there any good recommendations anyone can provide for a good Javascript editor on
Are there any good references for synchronisation algorithms? I'm interested in algorithms that synchronize
Is there any good way to handle a forced exit in C#? I have

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.