tags:

views:

347

answers:

7

The idea in the following is the first @font-face is for Firefox, the second for IE, and Arial for anything else that can't make sense of the first two. Its all working except for I want to give a different size in the case of Arial, and haven't figured out the syntax to do that.

@font-face {
  font-family: Tribeca;
  src: url("Tribeca.ttf"); format("truetype");
}

@font-face {
  font-family: TribecaIE;
  src: url("Tribec0.eot");
}

BODY
{
    FONT-FAMILY: Tribeca, TribecaIE, Arial; font-size: 195%;
}
A: 

This is no supported by normal CSS rules..

I believe your options are

  • the font-size-adjust property of css 3
  • javascript (jQuery), and check for current font to see which one of the three is effective and adjust the font-size accordingly..http://www.w3.org/TR/css3-fonts/#font-size-adjust ( you should also have a look at the http://www.modernizr.com/ )
Gaby
Actually I figured it out below, but thanks anyway.
Mark
Wait no, its not working.
Mark
A question related to my problem actually is this: I know on my Firefox it will do software updates without permission which I find kind of presumptuous, (I'm sure there's an option to turn it off) but are most people using Firefox getting the most current version inevitably (i.e. the one that supports @font-face.)
Mark
`Tools -> Options -> Advanced -> Update(tab)` for the software updates of firefox.. Usually firefox users will be quite up-to-date, because having selected firefox over IE means that they are a bit worried about their browsing experience.. (*i know this is argumentative.. just my opinion*)
Gaby
A: 
BODY
{
    FONT: 140% Arial;
    FONT: 195% Tribeca,TribecaIE;
}
Mark
Just to be clear, this doesn't appear to be the solution. In further repsonse to Gaby, I read that font-size-adjust isn't really all that well supported yet ( and my core problem here is support for older browsers). Also incredibly, it requires that you specify the aspect ratio of one of your fonts, as if anyone would know that. ALso both it and modernizr seem sort of like overkill to do something it seems browsers should be able to do to begin with , given that thy're able to use an alternate font (the three I just mentioned) So why not alternate font sizes - doesn't make any sense.
Mark
I can understand and share (*along with all web developers*) the frustration that comes from the multitude of incompatibilities and the lack of existing features in the standards.. it is an evolving process though .. and we are getting there (*i like to think..*).
Gaby
It isn't the solution. The second definition of the font property overrides the first, it doesn't provide a fallback.
David Dorward
A: 

I don't believe this is possible with css alone; we will probably need to use javascript.

All we want to do is specify a different font-size if Arial is the active font. Detecting the active font is not exactly straightforward, but here is one method that will work for our particular purpose. We can create a temporary element containing some Arial characters and measure its width, and then create a second element containing characters without specifying a font (so that it defaults to the "active" font) and compare widths. This won't tell us which font is currently active, but can indicate whether or not one of the embedded fonts was loaded with @font-face as they certainly won't have the same width as Arial. If the two elements' widths aren't equal we know that Arial could not have loaded, and so we will only adjust the font-size if the widths are equal.

Even if the browser is unable to load the Arial font, our test is still functional, because when we specify Arial during the test, the browser will default to the same font as it would for the second element. Both elements will still have equal width if the browser is unable to load the embedded fonts with @font-face.

If anyone would like me to further illustrate with code, I'll be happy to write the javascript.

Dustin Fineout
+1  A: 

I believe it is this (close to what you have):

@font-face {
  font-family: Tribeca;
  src: url("Tribeca.ttf");
}

@font-face {
  font-family: Tribeca;
  src: url("Tribeca.eot");
}

body {
    font-family: Tribeca, Arial;
}

IE won't know how to open the ttf, so it won't bother. Then it will open the eot. Then, you just specify the font by the given name in the body declaration.

geowa4
true, but afaik IE will still download the .ttf file, and then download the .eot file.
widyakumara
A: 

Target your browsers by knowing which one reads which type of declaration. Conditional Comment load different CSS calls. Then you can specifically tell each one to do something different per rule.

Also there is typekit

Lorenzo816
A: 
@font-face {
    font-family: 'Tribeca';
    src: url(Tribeca.eot);
    src: local('Tribeca'), url(Tribeca.ttf) format('truetype');
    }

MSIE will ignore the last line cos it doesn't understand format rule. and yes as pointed by porneL above, format() should go in the src property.

local() will make supporting browsers use local font file if user has it instead of downloading from your server (and probably make IE ignore the line too).

as for the font-size adjustment, as pointed by Gaby: CSS 3 font-size-adjust. but it looks like it's not widely supported, yet.

widyakumara
A: 

To void code duplication with @font-face, you can do this via server side. If you use for example some urlrewrite, detect UA, if it's IE - return file with .eot extension, if it's normal browser - ttf.

As for me, it works great.

And for this case, you shouldn't change your css files, just should have 2 files: .ttf & .oet.

Alex Ivasyuv