2017-04-05 21 views
0

我打電話給我的字體像這樣:404錯誤,當IE加載字體

@font-face { 
    font-family: 'dinar'; 
    src: url('../fonts/dinarm.eot?#'), 
     local('?'), 
     local('Mj_Dinar Two Medium'), 
     url('../fonts/dinarm.woff') format('woff'), 
     url('../fonts/dinarm.ttf') format('truetype'), 
     url('../fonts/dinarm.svg') format('svg'); 
    font-weight: normal; 
    font-style: normal 
} 
@font-face { 
    font-family: 'font-bmi'; 
    src: url('../fonts/font-bmi/font-bmi.eot'); 
    src: url('../fonts/font-bmi/font-bmi.eot') format('eot'), 
     url('../fonts/font-bmi/font-bmi.woff') format('woff'), 
     url('../fonts/font-bmi/font-bmi.ttf') format('truetype'); 
    font-weight: normal; 
    font-style: normal 
} 

每次使用Internet Explorer一些用戶嘗試,我看到很多404錯誤的虛擬主機使用日誌訪問該網站,最終用戶被我的安全插件禁止。有使用日誌的例子:

80.00.000.146 - - [05/Apr/2017:00:46:10 +0430] 
"GET /wp-content/themes/fonts/font-bmi/font-bmi.eot)%20format(%22eot%22), 
%20url(../fonts/font-bmi/font-bmi.woff)%20format(%22woff%22), 
%20url(../fonts/font-bmi/font-bmi.ttf)%20format(%22truetype%22 HTTP/1.1" 404 4058 
"http://www.21tech.ir/some-page/" "Mozilla/4.0 
(compatible; MSIE 8.0; Windows NT 5.1; --some other information--)" 

我知道它寫Mozilla/4.0但它實際上IE瀏覽器我測試過它。

什麼問題,以及如何解決或避免?

+0

的路徑應該是相對的CSS文件本身,而不是從調用CSS頁面。這是正確的道路嗎? – iguypouf

+0

@iguypouf是的,它只是發生在IE瀏覽器。 – ata

回答

1

原因是IE的舊版本無法正確解釋第二個@font-face聲明中的第二個src屬性。 (?)的解決方案,稱爲Fontspring @font-face syntax是一個問號追加到該屬性的.eot URL的末尾,欺騙IE以爲隨後的一切是一個查詢字符串:

@font-face { 
    font-family:"font-bmi"; 
    src:url("../fonts/font-bmi/font-bmi.eot?#iefix") format("embedded-opentype"), 
     url("../fonts/font-bmi/font-bmi.woff2") format("woff2"), 
     url("../fonts/font-bmi/font-bmi.woff") format("woff"), 
     url("../fonts/font-bmi/font-bmi.ttf") format("truetype"); 
    font-weight:normal; 
    font-style:normal 
} 

你已經試過一些不同的「黑客」可以在你的第一個@font-face聲明中解決這個問題,但是,儘管你已經成功地設法阻止IE報告404s,但上述解決方案更加清晰並且不會影響CSS的可讀性。

如要進一步瞭解,請參閱保羅愛爾蘭的「Bulletproof @font-face syntax」的文章從2009年

+0

其實我看到我的每一個字體的錯誤,第一個不好,我只是粘貼部分錯誤。我嘗試了你的建議,但沒有成功。 – ata

+0

你的答案的第一個鏈接,做了這份工作。謝謝。 – ata

+0

你必須做出什麼改變,它與我的解決方案有什麼不同? – Shaggy