日期:2014-05-17 浏览次数:20803 次
.ellipsis {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;/* IE/Safari */
-ms-text-overflow: ellipsis;
-o-text-overflow: ellipsis;/* Opera */
-moz-binding: url("ellipsis.xml#ellipsis");/*FireFox*/
}
<a class="ellipsis" style="width:200px" href="#">Test Test Test Test Test Test Test</a>
<div style="width:200px; border: 1px solid green;"><span class="ellipsis" style="float: left;border-right: 1px solid #ccc; margin-right: 4px; padding-right: 5px;" href="#">Othella Othella Othella Othella</span><span style="">female</span> </div>
fnAutoWidth = function(elements) {
var $span = $("<span style=\"white-space:nowrap;position:absolute;top:-9999px;font-size:12px;\"></span>").appendTo($("body"));
$(elements).each(function() {
var $elem = $(this),
realWidth;
$span.text($elem.text());
realWidth = $span[0].offsetWidth;
if (realWidth < $elem.width()) {
$elem.css("width", realWidth + "px");
}
});
$span.remove();
};