开发者

google web fonts aren't working on a web server

@font-face {
  font-family: 'Open Sans';
  font-styl开发者_如何学编程e: normal;
  font-weight: 400;
  src: local('Open Sans'), local('OpenSans'), url('cJZKeOuBrn4kERxqtaUH3bO3LdcAZYWl9Si6vvxL-qU.woff') format('woff');
}

@font-face {
  font-family: 'Open Sans';
  font-style: normal;
  font-weight: 300;
  src: local('Open Sans Light'), local('OpenSans-Light'), url('DXI1ORHCpsQm3Vp6mXoaTaRDOzjiPcYnFooOUGCOsRk.woff') format('woff');
}

I downloaded the fonts from the url the google css provided so I could use it without being online. The code works when clicking the .html file and opening it in a browser. However, when I place all my files on a local webserver it does not work.

Any ideas? Keep in mind, I will not be connected to the internet.


Adam there might be various reasons for this behavior as @Kyle suggested

First i would check the url to the font-file resolves correctly. From your CSS declaration above it seems that browser will expect the file to be present in same directory where CSS exists

Second and yes google might have blocked leeching/downloading the files. Only way to check this is first use the font to be loaded from google service 'Note the size of the file' then download and check the size. If they are same they do allow download

Third webfonts need to be browser specific here is the explanation from themselves

When a browser sends a request for a Font API stylesheet (as specified in a tag in your web page), the Font API serves a stylesheet generated for the specific user agent making the request.

so each time your browser requests the font you are actually downloading a small CSS snippet and then the Font family from the directory


Its strange if the font works fine on computer by opening html file, but not with the localhost. Are you sure you are copying all font files and placing in the same directory? Since the file name is so complicated and long, may be you are doing some mistake with the names? Are you using same browser?

And no, There is nothing like Google does not let downloading the files. Just to make sure, I have downloaded a font (GloriaHallelujah) from google fonts and tested with following code.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
    <title>Google font test</title>
    <style type="text/css" media="screen">
    @font-face {
        font-family: GloriaHallelujah;
        src: url('GloriaHallelujah.ttf');
        }   
    h1 { font-family: GloriaHallelujah, helvetica, arial; }     
    </style>
</head>
<body>
     <h1> Hello World </h1>
</body>
</html> 

This work fine on desktop, as well as local host. May be you can download same font from here, place in the same directory and then test on your localhost and see.


On my Windows 7 IIS server I had to add woff in the mime types to get them to work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜