2013-05-06 67 views
0

我喜歡這四條@font-face規則在我的CSS:字體是沒有得到加載

@font-face { 
    font-family: 'Ubuntu'; 
    font-style: normal; 
    font-weight: 400; 
    src: url(fonts/Ubuntu-Regular.ttf) format('truetype'); 
} 

和文件結構如下:

/index.html 
css/ 
    ... 
    fonts.css 
    fonts/ 
      Ubuntu-Regular.ttf 

在使用瀏覽器,我可以達到網址css/fonts/Ubuntu-Regular.ttf和文件正在下載。但是,它沒有被CSS加載的字體。我是否濫用url()

+1

你試圖清除你的緩存嗎? – Alarid 2013-05-06 12:45:36

+1

你看到了什麼瀏覽器?您可能還需要對差異瀏覽器的不同支持,例如:WOFF和EOT文件 – Riskbreaker 2013-05-06 12:53:56

+0

您是否在CSS中爲您需要的元素設置了font-family? – Rob 2013-05-06 13:42:45

回答

3

您需要的字體的各種版本的它在所有的瀏覽器。你可以得到你所需要的字體文件,與CSS一起,在FontSquirrel網站:

http://www.fontsquirrel.com/fonts/ubuntu

只需單擊「web字體工具包」鏈接在菜單中。

提供的CSS代碼如下:

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

+1爲http://www.fontsquirrel.com/ – mehdi 2013-05-06 13:07:37

+0

這是偉大的建議!它應該爲我做。 – rubik 2013-05-06 19:59:51

0

使用的所有字體文件.eot.woff.ttf對於所有瀏覽器..

@font-face {  
    font-family: 'Ubuntu'; 
    font-style: normal; 
    font-weight: 400; 
    src:url('fonts/Ubuntu.eot') format('eot'), 
      url('fonts/Ubuntu.woff') format('woff'), 
      url('fonts/Ubuntu.ttf') format('truetype'); 
} 
+0

我沒有所有這些版本,但使用@ ralph.m建議(fontsquirrel)我想我會解決這個問題。 – rubik 2013-05-06 20:00:25

1

你可以試試這個。只是害蟲下面的代碼在你的HTML頭標記

http://fonts.googleapis.com/css?family=Ubuntu:300,400' 的rel = '樣式' 類型= '文本/ CSS'>

&在你的css特定類中添加如下元素

font-family:'Ubuntu',sans-serif;

由於Ubuntu是谷歌字體,你不需要使用字體。你可以直接使用這個字體從http://www.google.com/fonts/ - 這個網站

+0

這就是我之前做的,但是因爲我必須在沒有互聯網連接的PC上使用這些文件(它們是impress.js演示文稿的一部分),所以我只想在本地加載字體。 – rubik 2013-05-06 19:59:12

相關問題