Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom font sometimes renders in italics in IE8 / IE7

In IE7 and IE8, when using a custom web font, text is sometimes rendered in italics, even when I explicitly set font-style: normal. The issue is sporadic - it will render fine a few times, then I refresh and everything is in italics, then I refresh and it's back to normal.

I'm using this @font-face declaration:

@font-face {
    font-family: 'DIN';
    src: url('fonts/DINWeb.eot');
    src: url('fonts/DINWeb.eot?#iefix') format('embedded-opentype'),
         url('fonts/DINWeb.woff') format('woff');
    font-weight: normal;
    font-style: normal;
}
@font-face {
    font-family: 'DIN';
    src: url('fonts/DINWeb-Bold.eot');
    src: url('fonts/DINWeb-Bold.eot?#iefix') format('embedded-opentype'),
         url('fonts/DINWeb-Bold.woff') format('woff');
    font-weight: bold;
    font-style: normal;
}
@font-face {
    font-family: 'DIN';
    src: url('fonts/DINWeb-Ita.eot');
    src: url('fonts/DINWeb-Ita.eot?#iefix') format('embedded-opentype'),
         url('fonts/DINWeb-Ita.woff') format('woff');
    font-weight: normal;
    font-style: italic;
}
@font-face {
    font-family: 'DIN';
    src: url('fonts/DINWeb-BoldIta.eot');
    src: url('fonts/DINWeb-BoldIta.eot?#iefix') format('embedded-opentype'),
         url('fonts/DINWeb-BoldIta.woff') format('woff');
    font-weight: bold;
    font-style: italic;
}

Theres a comment on this article that indicates it could be about the order of the @font-face declarations: however the only thing that stopped the problem was removing the italic declarations altogether.

Another Stack Overflow answer suggests using the Font Squirrel @font-face generator; I'm not able to do this however as the web font files I'm using have DRM.

Is there a way to solve this without completely removing the italic declarations?

UPDATE: Upon further investigation, it seems this issue affects IE8 as well, not just in compatibility mode.

like image 243
Adam Sharp Avatar asked Jul 09 '12 07:07

Adam Sharp


People also ask

Which CSS property can be used to italicize text?

The CSS property font-style is the one you need for making text italic, which you can apply to any selector you like.

What are font-style properties?

The font-style property allows you to make text appear italicized (i.e. sloped, or slanted). This property accepts one of three possible values: normal , italic , and oblique . If a given font family has an italic or oblique face embedded, the browser will select that face.

What does the font-style property adjust?

The font-style CSS property sets whether a font should be styled with a normal, italic, or oblique face from its font-family .


2 Answers

For each of your @font-face font-family names, create a custom name instead.

Example:

@font-face {
    font-family: 'DINnormal';
    src: url('fonts/DINWeb.eot');
    src: url('fonts/DINWeb.eot?#iefix') format('embedded-opentype'),
         url('fonts/DINWeb.woff') format('woff');
    font-weight: normal;
    font-style: normal;
}
@font-face {
    font-family: 'DINbold';
    src: url('fonts/DINWeb-Bold.eot');
    src: url('fonts/DINWeb-Bold.eot?#iefix') format('embedded-opentype'),
         url('fonts/DINWeb-Bold.woff') format('woff');
    font-weight: bold;
    font-style: normal;
}
@font-face {
    font-family: 'DINitalic';
    src: url('fonts/DINWeb-Ita.eot');
    src: url('fonts/DINWeb-Ita.eot?#iefix') format('embedded-opentype'),
         url('fonts/DINWeb-Ita.woff') format('woff');
    font-weight: normal;
    font-style: italic;
}
@font-face {
    font-family: 'DINboldItalic';
    src: url('fonts/DINWeb-BoldIta.eot');
    src: url('fonts/DINWeb-BoldIta.eot?#iefix') format('embedded-opentype'),
         url('fonts/DINWeb-BoldIta.woff') format('woff');
    font-weight: bold;
    font-style: italic;
}

After those CSS rules are defined, then you can include specific CSS rule:

li {
  font: 18px/27px 'DINnormal', Arial, sans-serif;
}
like image 64
arttronics Avatar answered Sep 29 '22 12:09

arttronics


If, like me, you came across this question while experiencing a similar issue using TypeKit fonts, this entry from the TypeKit blog explains how you can force unique font-family names for each weight & style of a TypeKit font to address it.

like image 31
poisontofu Avatar answered Sep 29 '22 12:09

poisontofu