限制网页上显示的字符串长度 [英] Limit displayed length of string on web page

查看:116
本文介绍了限制网页上显示的字符串长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种技术(javascript,CSS,任何???),它将让我控制显示的字符串的数量。字符串是搜索的结果(因此不是最初已知的)。一个简单的字符计数方法是微不足道的,但不能接受,因为它需要处理比例字体。换句话说,如果我想限制说70个像素,下面的例子显示不同的字符计数(9和15)两个测量相同: -

I'm looking for a technique (javascript, CSS, whatever ???) that will let me control the amount of a string that is displayed. The string is the result of a search (and therefore not initially known). A simple Character count approach is trivial, but not acceptable, as it needs to handle proportional fonts. In otherwords if I want to limit to say 70 pixels then the examples below show different character counts (9 and 15) both measuring the same:-

欢迎M ...

如果我有... I / I>

Welcome M...
Hi Iain if I've ...

如果您查看Yahoo搜索结果,他们可以限制标题字符串的长度,省略号在长字符串的末尾指示更多。
(试试网站:loot.com wireless + keyboard + and + mouse to see a example of Yahoo get this)

If you look at Yahoo search results they are able to limit the length of title strings and add ellipsis on the end of long strings to indicate more. (try site:loot.com wireless+keyboard+and+mouse to see an example of Yahoo achieving this)

任何想法?

推荐答案

也许CSS属性 overflow:hidden; 可以帮助你, c $ c> width 。

Perhaps the CSS property overflow: hidden; can help you, in conjuntion with width.

这篇关于限制网页上显示的字符串长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆