2014-11-04 82 views
0

我已經在網上搜索過,發現很多文章和教程,我跟着其中的一些,但仍然沒有得到想要的結果。如何使用CSS自定義字體?

我已經下載了字體並將其放置在我的項目文件夾中。這是我正在編寫的代碼,但它不會更改字體樣式。

@font-face 
{ 
    font-family: Montereybold; 
    src: url(font/Montereybold.ttf); 
} 

h1 
{ 
    font-size:36px; 
    font-family:Montereybold; 
} 

請引導我在這裏做錯了什麼。

謝謝

+0

到這個網址http://css-tricks.com/snippets/css/using-font-face/ – 2014-11-04 11:23:36

+0

打開控制檯,看看它是否會拋出一個404「無法找到文件」如果它確實那麼你的路徑可能是錯的 – user2209644 2014-11-04 11:30:11

+0

你會在這裏找到幾個自定義字體,請檢查http://www.google.com/fonts – 2014-11-04 11:31:23

回答

1

¿您是否嘗試過引用字體名稱?另外,爲了更好的兼容性,請上傳幾種字體格式。

@font-face { 
    font-family: 'Montereybold'; 
    src: url('font/Montereybold.eot'); /* IE9 Compat Modes */ 
    src: url('font/Montereybold.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */ 
    url('font/Montereybold.woff') format('woff'), /* Modern Browsers */ 
    url('font/Montereybold.ttf') format('truetype'), /* Safari, Android, iOS */ 
    url('font/Montereybold.svg#Montereybold') format('svg'); /* Legacy iOS */ 
    font-weight:normal; 
    font-style:normal; 
} 

使用它:

font-family:'Montereybold'; 
1

也許這個網址是錯誤的。你的css文件的父文件夾中是否有「font」文件夾?否則,請嘗試「../font/Montereybold.ttf」。

此外,所有瀏覽器都不支持ttf。使用font-face生成器可獲得最佳效果:http://www.fontsquirrel.com/tools/webfont-generator