简体   繁体   中英

font-family crash with @font-face src

Good day,

I have a css, code is as follow:

@font-face {
    font-family: 'dax-regularregular';
    src: url('../fonts/daxregular-webfont.eot');
}

body {
    font-family: 'dax-regularregular';
}

And, in my html code, I simply code:

<b>this is bold</b> + this is normal

And this is display correctly in chrome, but not in IE (All become normal, not bold).

If I remove the body{} in my css file, then IE will working fine. If I remove either font-family or src inside @font-face, then IE will working fine.

I do some research on internet, found that .eot file will not support for chrome, that's why chrome wont affected and display correctly. (Not sure my understanding is correct or not)

Kindly advise. And suggest your solution if you have.

** Edit **

@font-face {
    font-family: 'dax-regularregular';
    src: url('../fonts/daxregular-webfont.eot'); 
    src: url('../fonts/daxregular-webfont.eot?#iefix') format('embedded-opentype'), 
         url('../fonts/daxregular-webfont.woff') format('woff'), 
         url('../fonts/daxregular-webfont.ttf') format('truetype'),
         url('../fonts/daxregular-webfont.svg#dax-regularregular') format('svg'),
         url('../fonts/daxbold-webfont.eot');
    font-weight: normal;
    font-style: normal;
}

** Edit version 2 ** This solution can fix IE 9, IE 10, and IE 11 issue. But, This solution introduce new issue to IE 8, which is , normal word will be bold, and the bold word will become "more bold" ( become fatter ). I saw from internet, IE 8 is not support the @font-face rule with the WOFF format (only support for EOT format). So, i take out those url except eot, but still facing the problem.

I change my css code to as follow, but still same hit issue in IE 8:

@font-face {
    font-family: 'dax-regularregular';
    src: url('../fonts/daxbold-webfont.eot');
    src: url('../fonts/daxbold-webfont.eot?#iefix') format('embedded-opentype');
    font-weight: bold;
    font-style: normal;
}

As your code shows that you have included only .eot format webfont in body in css. The .eot format will work only on IE.

Now since you have added only url('../fonts/daxregular-webfont.eot') [notice 'regular'], the IE browser showing your text in regular or not-in-bold format. So if you want to display your text in-bold format on IE, you would need to add an additional url('../fonts/daxbold-webfont.eot') [notice 'bold'] definition in your css and also the relevant font in your font folder.

Now, why chrome displays it properly? I doubt if chrome would be showing your text in your desired font ie dax or .eot . Since you have not defined .woff font in your css (which chrome normally requires), most probably using some other font defined in some other css on your page.

To display your page consistently across all browsers using for custom font you would need to add all fonts definition in your css including adding the same in your font folder -

`@font-face {
  font-family: 'dax-regularregular';
  src: url('../fonts/daxregular-webfont.eot');
  src: url('../fonts/daxregular-webfont.eot?#iefix') format('embedded-opentype'),
       url('../fonts/daxregular-webfont.woff2') format('woff2'),
       url('../fonts/daxregular-webfont.woff') format('woff'),
       url('../fonts/daxregular-webfont.ttf')  format('truetype'),
       url('../fonts/daxregular-webfont.svg#svgFontName') format('svg');
}`

UPDATE:

First, other then font definition mentioned above you'll also have to add other font formats definitions in your css like

for bold,

@font-face {
      font-family: 'dax-bold';
      src: url('../fonts/daxbold-webfont.eot');
      src: url('../fonts/daxbold-webfont.eot?#iefix') format('embedded-opentype'),
           url('../fonts/daxbold-webfont.woff2') format('woff2'),
           url('../fonts/daxbold-webfont.woff') format('woff'),
           url('../fonts/daxbold-webfont.ttf')  format('truetype'),
           url('../fonts/daxbold-webfont.svg#svgFontName') format('svg');
    }

for semibold,

@font-face {
      font-family: 'dax-semibold';
      src: url('../fonts/daxsemibold-webfont.eot');
      src: url('../fonts/daxsemibold-webfont.eot?#iefix') format('embedded-opentype'),
           url('../fonts/daxsemibold-webfont.woff2') format('woff2'),
           url('../fonts/daxsemibold-webfont.woff') format('woff'),
           url('../fonts/daxsemibold-webfont.ttf')  format('truetype'),
           url('../fonts/daxsemibold-webfont.svg#svgFontName') format('svg');
    }

and so on including relevant fonts in font folder, whichever you need.

Second, for getting these fonts. Not sure but I think your dax font seems a licensed font and not the free one. If yes, then you can convert all above mentioned formats using the ttf / otf font which would have been installed in your system's 'Font' folder. To convert just copy the 'regular' or 'bold' font from that font folder on your desktop and then convert it using website like 'Font Squirrel'

UPDATE 2

  1. The IE needs .eot version web-font only, having .woff won't affect text in any IE version. So don't fear of .woff .

  2. You need to correct your font definition, which is still incorrect in your last post -

for regular or unbold font,

@font-face {
    font-family: 'dax-regularregular';
    src: url('../fonts/daxregular-webfont.eot');
    src: url('../fonts/daxregular-webfont.eot?#iefix') format('embedded-opentype');
}

for bold format font,

@font-face {
    font-family: 'dax-bold';
    src: url('../fonts/daxbold-webfont.eot');
    src: url('../fonts/daxbold-webfont.eot?#iefix') format('embedded-opentype');
}

Your html should look like this -

<p style="font-family: 'dax-regularregular';"><span style="font-family: 'dax-bold';">bold text lying here</span> unbold text lying here</p>

It should work proper across.

Note: Have shown applying font in inline tag to demonstrate html structure, please use your class for the same.

Try adding different types of fonts and specifying there type as well..

@font-face {
  font-family: 'dax-regularregular';
  src: url('../fonts/daxregular-webfont.eot'); /* IE9 Compat Modes */
  src: url('../fonts/daxregular-webfont.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
       url('../fonts/daxregular-webfont.woff2') format('woff2'), /* Super Modern Browsers */
       url('../fonts/daxregular-webfont.woff') format('woff'), /* Pretty Modern Browsers */
       url('../fonts/daxregular-webfont.ttf')  format('truetype'), /* Safari, Android, iOS */
       url('../fonts/daxregular-webfont.svg#svgFontName') format('svg'); /* Legacy iOS */
}

Add more font file like

font-family: 'dax-regularregular';
src: url('dax-regularregular.eot');
src: url('dax-regularregular.eot?#iefix') format('embedded-opentype'),
     url('dax-regularregular.woff') format('woff'),
     url('dax-regularregular.ttf') format('truetype'),
     url('dax-regularregular.svg#open_sansregular') format('svg');

Generate your font blow link

http://www.fontsquirrel.com/tools/webfont-generator

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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