text-overflow:ellipsis in Firefox. Pure CSS solution.

by Admin 28. February 2009 02:57

"Having the ability to chop long lines of text at the edge of a content area and show three dots to indicate there is some missing."

http://www.css3.info/preview/text-overflow/ 

While it's something that IE6 has been able to do since the 90s and most other browsers now support, Firefox has still been lacking in this area for some time.

Obviously you can trim the text on the server before sending it to the client but you cannot guarantee which font or indeed which font-size the user is using so this will always be a best guess not a science.

I've seen a few reasonable attempts at solving this over the years but none have ever come quite as close as this one to being workable. 

Firefox *should* be able to do this easily. After all, the tabs often contain an ellipsis when the page title is too long.

This solution is actually a cleaned up version of HedgerWow's script based XUL solution and a pure CSS delivery method by Rikkert Koppes.

To get it working normally first...

.ellipsis
{
 overflow: hidden;
 white-space: nowrap;
 text-overflow: ellipsis;
}

 ...to get it working in firefox as well, you will also need to do this...

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

Where ellipsis.xml is a  

<?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>

Known issues:

This solution doesn't work for innerHTML, only innerText.

The text cannot be selected by the user.

A tooltip should in theory be possible but I haven't looked into this fully yet.

 

Sources: 

http://www.rikkertkoppes.com/thoughts/2008/6/ 

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Comments

4/8/2009 9:26:23 PM

Franchises

Hey, nice blog theme. I have been thinking about using blogengine.net myself and am browsing around a few to check them out.

Cheers

Matthew Anderson

Franchises gb

7/29/2009 6:44:33 PM

Larry Gerndt

Beautiful post. Concise, and it works like a charm. Thank you so much!

Larry Gerndt us

7/31/2009 4:17:06 AM

Larry Gerndt

I've noticed something odd about using this technique: In FireFox, the text seems to render a few pixels higher than it would otherwise be rendered. I'm not sure what's causing this.

Larry Gerndt us

7/31/2009 5:33:18 AM

Larry Gerndt

Warning: As mentioned in http://www.rikkertkoppes.com/thoughts/2008/6/ , this solution causes CSS line-height to not be honored on the element containing the text.

Larry Gerndt us

8/29/2009 1:49:52 PM

reggae

Thanks for sharing such useful code for Pure CSS solution. Thanks

reggae us

9/5/2009 12:17:08 PM

Photo to Pop Art

Wonder full writing skills you got mate.


Regards

katiz

Photo to Pop Art us

9/29/2009 1:32:13 PM

Blocked Drain

I am engaged in css coding and site / control positioning at the moment and got drawn by the posting, " CSS Ninja textoverflowellipsis in Firefox Pure CSS solution " , in the search engines. The ambition of utilising css styles to get a satisfactory page structure in all the major browsers, Internet Explorer, Firefox, Safari and Google Chrome can be a great head ache that usually takes numerous hours to solve. Absorbing to study your views and the comments in your website on the issue. I feel the tutorial sites are inert and mention the same points, discussion in web logs frequently addresses actual methods to resolve issues or the most effective ways to set about online design. Thanks for the article.

Blocked Drain gb

10/14/2009 2:00:02 PM

finnish translation

Thanks mate!I was looking for that solution nearly all day!There are few more questions that I want to ask you.Should I post them as comments?By the way -I love your blog,awesome!!!You saved my a** again!

Regards,
Nick

finnish translation

10/16/2009 4:49:11 PM

Kerja Keras Adalah Energi Kita

Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic. If possible, as you gain expertise, would you mind updating your blog with more information? It is extremely helpful and beneficial to your readers.

Kerja Keras Adalah Energi Kita us

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET 1.4.0.0