jQuery - 添加省略号、断线,但不截断

发布于 2024-12-05 23:41:07 字数 288 浏览 4 评论 0原文

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

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

感谢您提供的任何帮助。

I would like to add ellipses to dynamic text contained within a scrollable div. However, I don't want the text to be truncated. I want the ellipses to be added, and then the text to continue on the next line. This is because the div only shows one line at a time, so the ellipses just lets the user know that there is more content and he is supposed to click the scroll arrows to continue reading.

What would be the best way to do this? ThreeDots http://tpgblog.com/threedots seems to be a very good plugin with lots of options, but I just don't know how to configure it to my need.

Thank you for any help you can give.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

策马西风 2024-12-12 23:41:07

为 DIV 提供高度,然后使用 text-overflow: ellipsis 并防止换行 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/

顺便说一句:如果您认为 Threedots 插件是一个更简单的选择,我建议您选择它。

Provide a height for your DIV, then use the text-overflow: ellipsis and prevent line-wrap CSS approach.

Here's a simple example:

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

Of course, there's always somebody making trouble, and this time it's Firefox. You have to bind a file to the CSS.

It's easier than you might think. Just create a new text file, and call it ellipsis.xml. Then stick it anywhere on your web server where you can reference it.

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

Then in your CSS, do this:

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

That's the quick run-down, and for more information check out this guy:

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

BTW: If you think the threedots plugin is an easier choice, I say go for it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文