CSS @font-face not working with Firefox, but working with Chrome and IE

后端 未结 28 2303
野趣味
野趣味 2020-11-22 06:27

The following code works in Google Chrome beta as well as IE 7. However, Firefox seems to have a problem with this. I\'m suspecting it to be a problem of how my CSS files ar

相关标签:
28条回答
  • 2020-11-22 06:34

    In addition to adding the following to your .htaccess: (thanks @Manuel)

    <FilesMatch "\.(ttf|otf|eot)$">
      <IfModule mod_headers.c>
        Header set Access-Control-Allow-Origin "*"
      </IfModule>
    </FilesMatch>
    

    You may want to try explicitly adding the webfont mime types to the .htaccess file... like this:

    AddType font/ttf .ttf
    AddType font/eot .eot
    AddType font/otf .otf
    AddType font/woff .woff
    

    In the end, my .htaccess file looks like this (for the section that enables webfonts to work in all browsers)

    # BEGIN REQUIRED FOR WEBFONTS
    
    AddType font/ttf .ttf
    AddType font/eot .eot
    AddType font/otf .otf
    AddType font/woff .woff
    
    <FilesMatch "\.(ttf|otf|eot|woff)$">
        <IfModule mod_headers.c>
            Header set Access-Control-Allow-Origin "*"
        </IfModule>
    </FilesMatch>
    
    # END REQUIRED FOR WEBFONTS
    
    0 讨论(0)
  • 2020-11-22 06:37

    I'd mention that some fonts have issues in firefox if their filename contains specific characters. I've recently run into an issue with the font 'Modulus' which had a filename '237D7B_0_0'. Removing the underscores in the filename and updating the css to match the new filename solved this problem. Other fonts with similar characters don't have this issue which is very curious...probably a bug in firefox. I'd recommend keeping filenames just to alphanumeric characters.

    0 讨论(0)
  • 2020-11-22 06:38

    May be its not because of your code, Its because of your Firefox configuration.

    Try this from Tool bar Western to Unicode

    View > Text Encoding > Unicode
    
    0 讨论(0)
  • 2020-11-22 06:39

    Try this....

    http://geoff.evason.name/2010/05/03/cross-domain-workaround-for-font-face-and-firefox/

    0 讨论(0)
  • This is a problem with how you setup your font-face's paths. Since you didn't start the path with a "/", Firefox will attempt to find the font's based on the path the stylesheet's in. So basically, Firefox is looking for your font in the "root/css/font" directory instead of the "root/font" directory. You can easily fix this by either moving the font folder to the css folder, or adding a / to the beginning of your font paths.

    Try this out:

    @font-face {
        font-family: "DroidSerif Regular";
        src: url("/font/droidserif-regular-webfont.eot");
        src: local("DroidSerif Regular"), url("/font/droidserif-regular-webfont.woff") format("woff"), url("/font/droidserif-regular-webfont.ttf") format("truetype"), url("/font/droidserif-regular-webfont.svg#webfontpB9xBi8Q") format("svg");
        font-weight: normal;
        font-style: normal;
    }
    @font-face {
        font-family: "DroidSerif Bold";
        src: url("/font/droidserif-bold-webfont.eot");
        src: local("DroidSerif Bold"), url("/font/droidserif-bold-webfont.woff") format("woff"), url("/font/droidserif-bold-webfont.ttf") format("truetype"), url("/font/droidserif-bold-webfont.svg#webfontpB9xBi8Q") format("svg");
        font-weight: normal;
        font-style: normal;
    }
    
    
    body {
        font-family: "DroidSerif Regular" , serif;
    }
    h1 {
        font-weight: bold;
        font-family: "DroidSerif Bold";
    }
    
    0 讨论(0)
  • 2020-11-22 06:41

    I had exactly the same problem. I had to create a new folder called "fonts" and put it in wp_content. I can access it from my browser like this http://www.example.com/wp-content/fonts/CANDY.otf

    Previously, the fonts folder was in the same directory as my CSS file, and the @font-face looked like this:

    @font-face { 
        font-family: CANDY;
        src: url("fonts/CANDY.otf");
    }
    

    As i mentioned above, this was not working in Firefox but only with Chrome. Now it is working because I used an absolute path:

    @font-face { 
        font-family: CANDY;
        src: url("http://www.example.com/wp-content/fonts/CANDY.otf");
    }
    
    0 讨论(0)
提交回复
热议问题