How to Achieve Cross-Browser Compatibility with @font-face and Correct MIME Types?

Susan Sarandon
Release: 2024-10-25 07:48:29
Original
813 people have browsed it

How to Achieve Cross-Browser Compatibility with @font-face and Correct MIME Types?

Cross Browser @font-face with Correct MIME Types

When using the @font-face rule to embed fonts, specifying the correct MIME type is crucial for proper rendering acrossbrowsers. In this case, Chrome displays an error due to incorrect MIME type.

To address this, let's examine a cross-browser compatible @font-face declaration:

@font-face {
  font-family: 'Graublau Web';
  src: url('GraublauWeb.eot');
  src: local('☺'),
         url('GraublauWeb.woff') format('woff'), url('GraublauWeb.ttf') format('truetype');
}
Copy after login
  • .eot for IE: IE requires the .eot file format.
  • .woff or .ttf for Other Browsers: Other browsers support either .woff or .ttf.

To generate these font formats from the source font, use Font Squirrel's font-face generator.

Additionally, an .htaccess file is required to specify the MIME types for the font formats:

AddType application/vnd.ms-fontobject .eot
AddType font/ttf .ttf
AddType font/otf .otf
AddType application/x-font-woff .woff
Copy after login

By implementing these changes, the @font-face rule will correctly embed fonts in both Firefox and Chrome, ensuring consistent rendering acrossbrowsers.

The above is the detailed content of How to Achieve Cross-Browser Compatibility with @font-face and Correct MIME Types?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!