2012-02-10 136 views
0

我正嘗試使用text-overflow: ellipsis截斷我網站上的文本。它在Firefox中正確顯示,但不顯示在IE中;我已經包括了我的代碼和它是如何顯示在Firefox和IE下面的例子:省略號在Internet Explorer上無法正常工作

.ellipsis { 
    font-weight: bold; 
    height: 1.2em; 
    overflow: hidden; 
    text-overflow: ellipsis; 
    white-space: nowrap; 
    width: 150px; 
} 

Elippis on IE and Firefox

+1

你試過'-ms-text-overflow:ellipsis;'? – 2012-02-10 03:23:23

+0

文本溢出在IE6中可用,因此您不需要使用Microsoft供應商前綴。 – tobint 2012-02-10 09:43:07

回答

0

我找到了解決辦法,因爲我用一個標籤來包裝div標籤,以便IE瀏覽器不能很好。

我把一個標籤移動到div標籤裏面,它工作的很好。感謝大家幫助我。

2

text-overflow一直available as of IE6,所以你並不需要使用Microsoft供應商前綴。不過,您可能需要Opera和Webkit的擴展,具體取決於您的網站計劃支持的內容。

您正在測試此版本的Internet Explorer的哪個版本?

很明顯,您可以很容易地使用jQuery plugin來實現同樣的功能,但如果IE是您唯一的問題,則應該不需要,因爲如前所述,它應該支持該功能。

下面是一個簡單的代碼複製,應該工作使用此功能:

<!DOCTYPE html> 
<html> 
<head> 
    <title>text-overflow: ellipsis</title> 
    <style type="text/css"> 
    .ellipsis { 
     height: 1.2em; 
     overflow: hidden; 
     text-overflow: ellipsis; 
     white-space: nowrap; 
     width: 150px; 
    } 
    </style> 
</head> 
<body> 
    <div class="ellipsis"> 
      This is a test of the less-than-emergency 
      broadcast system. This is only a test. 
    </div> 
</body> 
</html>