1

我想将省略号添加到可滚动 div 中包含的动态文本中。但是,我不希望文本被截断。我希望添加省略号,然后文本在下一行继续。这是因为 div 一次只显示一行,所以省略号只是让用户知道还有更多内容,他应该单击滚动箭头继续阅读。

最好的方法是什么?ThreeDots http://tpgblog.com/threedots似乎是一个非常好的插件,有很多选项,但我只是不知道如何根据我的需要配置它。

感谢您提供的任何帮助。

4

1 回答 1

1

为您的 DIV 提供一个高度,然后使用text-overflow: ellipsisand prevent line-wrap CSS 方法。

这是一个简单的例子:

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

当然,总会有人惹麻烦,这次是火狐。您必须将文件绑定到 CSS。

这比你想象的要容易。只需创建一个新的文本文件,并将其命名为 ellipsis.xml。然后将其粘贴到您的网络服务器上任何可以引用的位置。

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

然后在您的 CSS 中,执行以下操作:

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

那是快速的失败,有关更多信息,请查看此人:

http://mattsnider.com/css/css-string-truncation-with-ellipsis/

BTW:如果你认为threedots 插件是一个更简单的选择,我说去吧。

于 2011-09-23T03:05:29.290 回答