如果 CSS 或 Asp.net 中的文本太宽,则剪切文本

发布于 2024-08-07 13:15:27 字数 523 浏览 3 评论 0原文

我在一个固定宽度的 div 中有这个文本:

Some headline (2009-10-10 small)
Some headline (2009-10-10 small)
Some headline (2009-10-10 large)

但是当标题太宽时,结果是:

Some headline (2009-10-10 small)
Some wide headline (2009-10-10
large)
Some headline (2009-10-10 large)

这不好看:/我真正想要的是:

Some headline (2009-10-10 small)
Some wide... (2009-10-10 large)
Some headline (2009-10-10 large)

这可以用 Asp.net 和 CSS 制作吗?我知道我可以在 Asp.net 中测量字符串宽度,但它(据我所知)不是很精确。

I have this text inside a div with a fixed width:

Some headline (2009-10-10 small)
Some headline (2009-10-10 small)
Some headline (2009-10-10 large)

But when the headline is too wide the result is:

Some headline (2009-10-10 small)
Some wide headline (2009-10-10
large)
Some headline (2009-10-10 large)

Which is not good looking :/ What I really wants is:

Some headline (2009-10-10 small)
Some wide... (2009-10-10 large)
Some headline (2009-10-10 large)

Is this possible to make with Asp.net and CSS? I know I can measure a string width in Asp.net but it (as I know) is not very precise.

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

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

发布评论

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

评论(2

左耳近心 2024-08-14 13:15:27

这就是我使用 mootools 的方法:

http://mooshell.net/34WbY/

将浏览器大小调整为看到魔法。

This is how I do it with mootools:

http://mooshell.net/34WbY/

Resize your browser to see the magic.

2024-08-14 13:15:27

您需要的是,如果文本超过一定的视觉长度,则将其截断。 CSS 可用于隐藏超出的字符,但截断必须在代码级别(服务器大小或 JavaScript)完成。

如果您尝试按字符数进行旋转,除非您使用的是固定宽度字体,否则这可能会有点棘手。或者,您可以尝试更保守的最大字符数。

我确信还有更多创造性的方法,我渴望“听到”其他人的意见。

What you need is to truncate the text if it exceeds a certain visual length. CSS can be used to hide the exceeding characters, but the truncation has to be done at code level (server-size or javascript).

This can be a little tricky if you are trying to turncate by character count unless you are using fixed-width fonts. Alternatively, you can try a more conservative max character count.

I'm sure there are more creative methods, I'm eager to 'hear' from the rest.

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