2015-10-13 89 views
0

我使用的是font-awesome,它可以很好地處理CSS文件的CDN擴展。下面是一個簡單的例子:font-awesome的字體文件的用途是什麼?

<html> 
    <head> 
     <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.4.0/css/font-awesome.css"> 
    </head> 
    <body> 
     <i class="fa fa-adjust"></i> 
    </body> 
</html> 

的例子運行正常,但是從the CDN,我也得到鏈接,.otf.eot.svg.ttf.woff文件。如果這個例子只適用於.css文件擴展名,那麼這些文件的用途是什麼?

+3

如果瀏覽器/操作系統不支持該字體,那麼將使用該字體 – Tushar

+1

這就是你的網絡字體,這些字體包含在主要的css文件「check section FONT PATH」中https://cdnjs.cloudflare.com/ajax/libs /font-awesome/4.4.0/css/font-awesome.css – SilentTremor

+0

@SilentTremor - 這意味着一旦我們包含了CSS,我們不需要在此之後添加這些其他文件?如果是這樣,爲什麼鏈接分開提供?任何具體原因? – Deadpool

回答

2

這是因爲如果你看到該css文件,你會發現導入或調用所有這些文件的鏈接或代碼。基本上CSS只是顯示和調用特定圖標的代碼。但該圖標位於那些otf和其他文件中。它就像你只能在html中調用img標籤一樣,但爲什麼你需要在你的網站上放置一個圖片才能保存在網站中。 希望它清除

感謝

+0

好的,但作爲用戶,現在我只需要調用.css文件的cdn。我永遠不需要從cdn(.otf,.ttf,.eot等)擴展其他文件? – Deadpool

+0

@Peterson不,它取決於瀏覽器。 – BFWebAdmin

+0

@BF - 但是,當所有其他文件都包含在.css文件中時(請參閱上面的鏈接),爲什麼我們仍然會在代碼中再次擁有外部鏈接(除了已經包含這些其他文件的.css文件之外字體文件的類型)? https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.4.0/css/font-awesome.css – Deadpool

6

雖然某些瀏覽器支持TTF/OTF格式的網絡字體,除非字體設置爲可安裝的嵌入模式的Internet Explorer生成一個錯誤。當向IE提供.woff和.eot變體時,都會重現此行爲。

這可以通過在字體文件中設置的Fstype標誌0000,表示可安裝嵌入模式,使用以下工具之一來補救: 使用ttembed-JS NPM模塊

npm install -g ttembed-js 
ttembed-js path/to/fontawesome-webfont.ttf 
ttembed-js path/to/FontAwesome.otf 

,或者內Node.js的:

var callback = function(error, oldFsType) { 
    if (error) { 
     console.error('Something went wrong.', error); 
     return; 
    } 
    if (oldFsType === '0000') { 
     console.log('fsType is already 0000; no action taken.'); 
    } else { 
     console.log('fsType successfully changed from ' + oldFsType + ' to 0000.'); 
    } 
} 
var ttembed = require('ttembed-js'); 
ttembed({filename: './path/to/fontawesome-webfont.ttf'}, callback); 
ttembed({filename: './path/to/FontAwesome.otf'}, callback); 

使用原裝ttembed

git clone https://github.com/hisdeedsaredust/ttembed.git 
cd ttembed 
make 
./ttembed path/to/fontawesome-webfont.ttf path/to/FontAwesome.otf