简体   繁体   English

font-face不适用于托管服务提供商

[英]font-face doesn't work on hosting provider

I have problem when I am hosting a web site: before hosting when i run web site locally in my computer the font was fine, but when hosting it, font doesn't work. 当我托管一个网站时我有问题:在托管之前,当我在我的电脑本地运行网站时,字体很好,但是当托管它时,字体不起作用。 (I use font for pdf on my web page, and i use dompdf to convert to pdf) (我在我的网页上使用pdf字体,并使用dompdf转换为pdf)

Here the code: 这里的代码:

        /* latin-ext */
        @font-face {
          font-family: 'Great Vibes';
          font-style: normal;
          font-weight: 400;
          src: local('Great Vibes'), local('GreatVibes-Regular'), url(./asset/fonts/font-sertifikat/sertifikat.woff2) format('woff2');
          unicode-range: U+0100-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF;
        }
        /* latin */
        @font-face {
          font-family: 'Great Vibes';
          font-style: normal;
          font-weight: 400;
          src: local('Great Vibes'), local('GreatVibes-Regular'), url(./asset/fonts/font-sertifikat/sertifikat4.woff2) format('woff2');
          unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215;
        }



        p.serif {
            font-family: 'Great Vibes';
            font-size: 70px;
            padding-top: 250px;
        }

在此输入图像描述

The web server for your hosting provider does (probably) not send the correct Content-Type header for the fonts, and as a result your browser refuses to load them. 您的托管服务提供商的Web服务器(可能)不会为字体发送正确的Content-Type标头,因此您的浏览器拒绝加载它们。

You need proper content type headers for fonts to work . 需要适当的内容类型标头才能使用字体

Can you inspect the response headers for the .woff2 files in the 'Networking' tab of your browser's dev tools? 您可以在浏览器开发工具的“网络”选项卡中检查.woff2文件的响应标头吗?

devtools http标头

If it's indeed missing (compare headers with local hosting), that's the problem. 如果它确实丢失了(比较标题与本地主机),那就是问题所在。 You need to get that server to insert http header Content-Type: font/woff2 (*). 您需要让该服务器插入http标头Content-Type: font/woff2 (*)。 And that will depend on your hosting provider. 这取决于您的托管服务提供商。 Maybe some will allow to do that in a .htaccess that you can install yourself in your site. 也许有人会允许你在.htaccess这样做,你可以自己安装在你的网站。

(*) edited: previous suggestion was application/font-woff2 . (*)编辑:以前的建议是application/font-woff2 See this answer , there are many others on that topic. 看到这个答案 ,关于该主题还有很多其他问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM