Cut of text if too wide in CSS or Asp.net

谁都会走 提交于 2019-12-10 00:32:52

问题


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.


回答1:


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.




回答2:


This is how I do it with mootools:

http://mooshell.net/34WbY/

Resize your browser to see the magic.



来源:https://stackoverflow.com/questions/1547943/cut-of-text-if-too-wide-in-css-or-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!