2015-04-03 72 views
0

我正在建立一個網站,需要通過@ font-face使用自定義字體。如果我使用.eot擴展名,IE只會顯示;其他瀏覽器只有當我使用.ttf擴展名。有條件的評論不起作用

雖然我已經在Web上嘗試了大量的建議,但我無法解決如何使用條件註釋來使用這兩種建議......沒有任何工作適合我。

從本質上講,我有:

<style> 
@font-face{ 
font-family: Square; 
src: url(/wpadmin/fonts/Square.ttf); 
} 

@font-face{ 
font-family: Square_IE; 
src: url(/wpadmin/fonts/Square.eot); 
} 

</style> 

<!--[if !IE]><!--> 
<style> 
#Title{ 
font-family:Square; 
} 
</style> 
<!--<![endif]--> 

<!--[if IE]><!--> 
<style> 
#Title{ 
font-family:Square_IE; 
} 
</style> 
<!--<![endif]--> 

字體只能在IE中顯示正確的位置 - 不能在其他瀏覽器。如果我刪除[如果IE]語句,它會在其他瀏覽器中正確顯示。

我已經嘗試了很多變體,包括HTML體內的條件語句。

我在做什麼錯?

+0

不知道,但我認爲[如果IE]部分應該是裏面的評論,讓其他瀏覽器會忽略它 – 2015-04-03 10:03:03

+0

你還沒說IE的什麼版本,但條件註釋不從版本工作11 – Tim 2015-04-03 10:03:51

+0

您必須使用'-ms-'作爲IE特定css的前綴。 – Rajeshwar 2015-04-03 10:06:25

回答

2

條件註釋在IE 11中不起作用,但這也不是標準方法。您不需要不同的字體名稱,您可以爲所有引用一個名稱的跨瀏覽器字體文件列表執行此操作。

/* declare all the files - browser will use the best it understands */ 

@font-face { 
    font-family: 'Square'; 
    src:url('Square.eot'); 
    src:url('Square.eot?#iefix') format('embedded-opentype'), 
     url('Square.ttf') format('truetype'), 
     url('Square.woff') format('woff'), 
     url('Square.svg#Square') format('svg'); 
    font-weight: normal; 
    font-style: normal; 
} 


/* now just reference the one name */ 

#Title { 
    font-family:Square; 
} 
+0

謝謝,蒂姆 - 它不工作 - 也就是說 - 它在IE中正確顯示,但不在其他瀏覽器中顯示... – JohnG 2015-04-03 10:17:29

+0

啊 - 現在工作 - 我調整了一下 - 謝謝。它似乎只喜歡一個src:行,而不是兩個。 – JohnG 2015-04-03 10:20:48

+0

我希望IE11無論如何都要使用TTF字體。 http://caniuse.com/#feat=ttf – Tim 2015-04-03 10:22:50