2016-11-24 46 views
0

此代碼在我的單個HTML頁面上正常工作,HTML文件和字體都位於同一文件夾中。@ font-face在本地工作,而在使用url時不工作

@font-face { 
    font-family: myFont; 
    src: url(DroidKufi-Regular.ttf); 
} 

現在我試圖在網站中添加字體並使用代碼中的鏈接。

src: url("http://hnauae.com/myFonts/DroidKufi-Regular.ttf"); 

這一個不工作,任何人都可以解釋我爲什麼?

+1

什麼是您收到的控制檯錯誤添加? – Roberrrt

+0

嘗試使用相對路徑而不是絕對路徑。 – claudios

+0

你在網站上使用https嗎?如果你使用https,那麼'src'也需要是https,以防止CORS錯誤 –

回答

-1

也許嘗試使用相對路徑而不是相對路徑。

請注意,它將取決於您的文件結構。

變化

src: url("http://hnauae.com/myFonts/DroidKufi-Regular.ttf"); 

src: url("../myFonts/DroidKufi-Regular.ttf"); 
+0

如果我使用這個代碼,src:url(「../ myFonts/DroidKufi-Regular.ttf」); –

0

導入鏈接使頁面加載比正常加載慢。 使用你的資源的本地

和使用如下相對路徑:

@font-face { 
    font-family: 'Roboto'; 
    src: url('fonts/roboto/Roboto-Thin-webfont.eot'); 
    src: url('fonts/roboto/Roboto-Thin-webfont.eot?#iefix') format('embedded-opentype'), 
     url('fonts/roboto/Roboto-Thin-webfont.woff') format('woff'), 
     url('fonts/roboto/Roboto-Thin-webfont.ttf') format('truetype'), 
     url('fonts/roboto/Roboto-Thin-webfont.svg#robotothin') format('svg'); 
    font-weight: 100; 
    font-style: normal; 
    /*other custom styles*/ 
} 
0

即使你嘗試在網站上使用相對路徑

相關問題