2010-10-11 17 views
11

可能重複:
Is it possible to implement the effect of overflow:ellipsis with javascript or css?
How do I indicate long text into a smaller fixed column with CSS?CSS:如何限制使用顯示文本 「...」

我要修剪文本,如果它是大於300像素寬「...」

例如,如果我有:

<ul> 
<li>this is greater than 300px, than only display as much of the text that is 300px wide and then replace the remaining text with "..."</li> 
<li>short, don't trim</li> 
</ul> 

將顯示爲:

this is greater than 300px, than only ... 
short, don't trim 
|----------- 300px wide ----------------| 

我將如何做到這一點與CSS/HTML?

+1

可能重複(HTTP:/ /stackoverflow.com/questions/2995656/)和http://stackoverflow.com/questions/3067696和http://stackoverflow.com/questions/802175/和http://stackoverflow.com/questions/486563/男子我我對這個問題感到無聊 – 2010-10-11 21:23:17

+0

我嘗試了上面的內容,並沒有使用** pure ** CSS/HTML。它只適用於我使用JQuery並且不想使用JQuery。 – Jason 2010-10-12 15:52:01

+0

**這可能是重複的,但我還沒有找到一個純CSS/HTML的答案,工程。有一些建議使用鏈接代碼,但代碼不起作用。** http://stackoverflow.com/questions/2108740/how-do-i-indicate-long-text-into-a-smaller-fixed-列與CSS/2109035#2109035 – Jason 2010-10-12 16:12:37

回答

11
+0

我試過上面的,它不工作使用**純粹的CSS/HTML。它只適用於我使用JQuery並且不想使用JQuery。 – Jason 2010-10-12 15:51:37

+0

@Jason你可以使用「本機」JS實現,但它與jQuery更短 – 2010-10-12 15:56:19

+0

我不是在尋找一個JS解決方案,我正在尋找一個使用純CSS/HTML的解決方案 – Jason 2010-10-12 16:14:16

3

對不起所有,我只是找到了答案在這裏 - >How do I indicate long text into a smaller fixed column with CSS?

的[是有可能實現的溢出效應?:JavaScript或CSS省略號]
+0

雖然這個鏈接可能會回答問題,最好在這裏包含答案的重要部分,並提供參考鏈接。如果鏈接頁面更改,則僅鏈接答案可能會失效。 – ProgramFOX 2014-03-06 17:59:56