0

I'm building a website which needs to use a custom font through @font-face. IE only displays if I use an .eot extension; other browsers only if I use a .ttf extension.

I can't work out though how to use conditional comments to use both - even though I've tried loads of suggestions on the web... Nothing's working for me.

Essentially, I have:

<style>
@font-face{
font-family: Square;
src: url(/wpadmin/fonts/Square.ttf);
}

@font-face{
font-family: Square_IE;
src: url(/wpadmin/fonts/Square.eot);
}

</style>

<!--[if !IE]><!-->
<style>
#Title{
font-family:Square;
}
</style>
<!--<![endif]-->

<!--[if IE]><!-->
<style>
#Title{
font-family:Square_IE;
}
</style>
<!--<![endif]-->

The font only displays correctly in IE here - not in other browsers. If I remove the [if IE] statement, it then displays correctly in other browsers.

I've tried lots of variations, including conditional statements within the html body.

What am I doing wrong?

5
  • Not sure, but I think the [if IE] part should be inside the comments, so that other browsers ignore it Commented Apr 3, 2015 at 10:03
  • You haven't said what version of IE, but conditional comments don't work from version 11 Commented Apr 3, 2015 at 10:03
  • You have to use -ms- as a prefix for IE specific css. Commented Apr 3, 2015 at 10:06
  • It is IE11 - I had heard that newer versions of IE don't support the comments... That's why I put !IE first, in the hope that other browsers would pick that up, but that IE would just be over-ridden by the second comment. But what's the solution then - can I not do conditional CSS at all with IE now? Commented Apr 3, 2015 at 10:07
  • Thanks Rajeshwar - but where? I tried -ms-font-family: within the #Title css, but it doesn't work... Can anyone point me to an example? Commented Apr 3, 2015 at 10:08

1 Answer 1

2

Conditional comments don't work from IE 11, but also this isn't the standard approach. You don't need different font names, you can just do this for a cross-browser list of font files all referencing one name.

/* declare all the files - browser will use the best it understands */

@font-face {
   font-family: 'Square';
   src:url('Square.eot');
   src:url('Square.eot?#iefix') format('embedded-opentype'),
       url('Square.ttf') format('truetype'),
       url('Square.woff') format('woff'),
       url('Square.svg#Square') format('svg');
    font-weight: normal;
    font-style: normal;
}


/* now just reference the one name */

#Title {
  font-family:Square;
}
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, Tim - it's not working either tho - with this it's displaying properly in IE but not in other browsers...
Ah - works now - I tweaked a bit - thank you. It seems to like only one src: line, rather than two.
I would expect IE11 to be using the TTF font anyway. caniuse.com/#feat=ttf

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.