如果 CSS 或 Asp.net 中的文本太宽,则剪切文本
我在一个固定宽度的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这就是我使用 mootools 的方法:
http://mooshell.net/34WbY/
将浏览器大小调整为看到魔法。
This is how I do it with mootools:
http://mooshell.net/34WbY/
Resize your browser to see the magic.
您需要的是,如果文本超过一定的视觉长度,则将其截断。 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.