使用Nginx代理解決
字體庫都在靜態資源引用里,把靜態引用地址全部代理出來。
# 跨域訪問字體問題
location ~*\.(eot|otf|ttf|woff|woff2|svg)$ {
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Headers X-Requested-With;
add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
}
# 靜態資源引用
location /hngsmm/web-base/ {
add_header Access-Control-Allow-Origin *;
proxy_pass http://192.168.1.123/web-base/;
}
location /hngsmm/forestar-base/ {
add_header Access-Control-Allow-Origin *;
proxy_pass http://192.168.1.123/forestar-base/;
}
location /hngsmm/forestarui/ {
add_header Access-Control-Allow-Origin *;
proxy_pass http://192.168.1.123/forestarui/;
}
解決@font-face跨域方法:
https://www.cnblogs.com/terrylin/p/3598962.html
https://m.daixiaorui.com/read/283.html
瀏覽器支持
![]()
![]()
![]()
![]()
![]()
Internet Explorer 9, Firefox, Opera,Chrome, 和 Safari支持@font-face 規則.
但是, Internet Explorer 9 只支持 .eot 類型的字體, Firefox, Chrome, Safari, 和 Opera 支持 .ttf 與.otf 兩種類型字體.
注意: Internet Explorer 8 及更早IE版本不支持@font-face 規則.
屬性定義及使用說明
@font-face規則,網頁設計師再也不必使用的"web-safe"的字體之一。
字體的名稱,font - face規則:
- font-family: myFirstFont;
字體文件包含在您的服務器上的某個地方,參考CSS:
- src: url('Sansation_Light.ttf')
如果字體文件是在不同的位置,請使用完整的URL:
- src: url('http://www.w3cschool.css/css3/Sansation_Light.ttf')

@font-face {
font-family: 'MyWebFont';
src: url('../font/webfont.woff') format('woff'),
url('../font/webfont.ttf') format('truetype');
}
@font-face {
font-family: 'UnidreamLED';
src: url("../font/UnidreamLED.ttf") format('truetype'),
url('../font/UnidreamLED.woff') format('woff');
}
conHead{
font-family: 'MyWebFont';
}
下載的字體打開一看,只有.ttf格式的字體文件,但是在@font-face屬性里,一般要引入.eot + .ttf /.otf + svg + woff 才能達到讓所有瀏覽器的完美支持。
那么我們就需要把.ttf文件轉換成字體的其他格式文件,可以在https://www.fontsquirrel.com里來操作
