Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@font-face and font-size

Tags:

css

fonts

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%;
}
like image 755
Mark Avatar asked Feb 06 '10 21:02

Mark


People also ask

What is font face and font size?

font size:it helps you to select the size of a leeter of font style which u have chosen. Like u chose Roman as font face the u select the context and apply 72 as font size so the context u have selected will appear larger.it helps to decrease or increase the size of the font..

What do you mean by font face?

The @font-face CSS at-rule specifies a custom font with which to display text; the font can be loaded from either a remote server or a locally-installed font on the user's own computer.

What is the difference between font and face?

Typeface vs.While a typeface describes a particular style of lettering, a font refers to variations of a typeface, like its size and weight. The simplest way to understand this difference is that a typeface is a set of fonts with common aesthetic qualities.


1 Answers

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.

like image 78
defines Avatar answered Nov 03 '22 15:11

defines