overflow:hiddenHowever, it's nice to show to users that some content is actually missing. This is typically done with an ellipsis character, that is displayed as three dots:
...Getting this working across all modern browsers has always been a pain in the neck, but there is
First, make sure you have a small
ellipsis-xbl.xml file on your web server that is served with the content type text/xml, with the following contents:<?xml version="1.0" encoding="UTF-8"?>Then mark all HTML elements you would like to show the ellipsis character on overflow with the class
<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>
Ellipsis, e.g.:<div id="BreadCrumbs" class="ShyText Ellipsis">Then add the following to your CSS:
.Ellipsis {
text-overflow:ellipsis;
-o-text-overflow:ellipsis;
-ms-text-overflow:ellipsis;
-moz-binding:url(/ellipsis-xbl.xml#ellipsis)
}Elaboration:- text-overflow
- for WebKit-based browsers (Safari, Chrome, etc.) and for Internet Explorer 7 and before;
- -o-text-overflow
- for Opera;
- -ms-text-overflow
- for Internet Explorer 8;
- -moz-binding
- for Gecko-based browsers (Firefox, Camino, etc.)
text-overflow will be standardized as of the CSS 3 standard, which is currently still in draft.Credit for the Gecko solution go to Rikkert Koppes and William Khoe, see the article text-overflow: ellipsis for firefox.
Update (Oct. 22, 2008): The solution for Gecko-based browsers (Firefox, etc.) is far from perfect. The solution has at least the following issues:
- applying the
.Ellipsisclass to an inline element causes the element to disappear; - in Firefox 3.0 (not in Firefox 2.0), soft hyphens inside
.Ellipsiselements always show as dashes; - text inside a
.Ellipsiselement can no longer be selected.
Update (August 13, 2009): Don't expect the solution to go into Firefox 3.6/Gecko 1.9.2 (scheduled for release fall 2009), the bug has been tagged as "-wanted1.9.2" (starting with a minus-sign) meaning it's not planned for the upcoming release. It may still go into Firefox 3.7, which is tentatively scheduled for release in 2010, see the Mozilla Project Meeting Minutes of July 20, 2009.
Update (August 24, 2009): Devon Govett provides a nice jQuery-based solution that at least allows you to resolve the issue when JavaScript is enabled. It works like a charm, at least on Firefox 3.5.2.
Thanks for this nice solution. Would it be equally effective to just add the custom styling where the problem currently appears? I am currently using a template where they are yousing ellpsis without providing a solution:/
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteI have one problem with this solution. If the html element contains a sequence of spaces, they get rendered by FF. If the html contains tabs they don't get rendered.
ReplyDeleteAny idea on how to fix this?
In this sample, the . represent spaces
[div class="ellipsis"]....Spaces not ok[/div]
@comecme: No idea how to fix that. Note that the 'solution' I provide is in fact just a dirty hack. The real solution should come from the Mozilla developers, see bug report 312156.
ReplyDeleteGreat extension. One bug, if there are child nodes (without any text), it will be truncated. Eg:
ReplyDelete[div class='ellipsis"][img src="some.gif" /][/div]
will break. Any idea?
I am working on this .
ReplyDeleteCan't you just unbind on :hover and fix most of these 'bugs'?
.Test {
text-overflow: ellipsis;
-o-text-overflow :ellipsis;
-moz-binding: url('ellipsis.xml#ellipsis');
border: 1px solid #ddd;
white-space: nowrap;
overflow: hidden;
padding:2em;
width:50%;
}
.Test:hover {
XXtext-overflow: normal;
-moz-binding: url('ellipsis.xml#blank');
XXoverflow: visible;
}
This solution is not working for me. I followed all the steps given here.
ReplyDeleteIt's worth pointing out that Firefox 4 is removing the ability to use XUL in this way, so this hack will no longer work.
ReplyDeleteHere's hoping they get round to implementing a proper CSS ellipsis in Firefox soon now -- it's starting to get old now that its *still* the only browser not to support it.
-o-text-overflow is not needed in Opera 11.
ReplyDeleteYou can use text-overflow instead of -ms-text-overflow in IE
Firefox 7 was released yesterday with support for ellipsis. For information see:
ReplyDeletehttps://developer.mozilla.org/en/CSS/text-overflow
Hi,
ReplyDeleteI want to display ellipses like "total value...^1" can i get one solution for this
Hi,
ReplyDeleteI want to display ellipses like "total value...^1" can i get one solution for this
Hello, How do I get in touch with you? There is no email or contact info listed .. please advise .. thanks .. Mary. Please contact me maryregency at gmail dot com
ReplyDelete