Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@font-face, font variants

This is my @font-face declaration to support different font variants, in this case the bold and bolder version of my font.

@font-face {
  font-family: "santana";
  src: url("data:font/ttf;base64,AAEAAAALAI....") format('truetype');
  font-weight: normal;
  font-style: normal;
}
@font-face {
  font-family: "santana";
  src: url("data:font/ttf;base64,AAEAAAALAI....") format('truetype');
  font-weight: bold;
}
@font-face {
  font-family: "santana";
  src: url("data:font/ttf;base64,AAEAAAALAI....") format('truetype');
  font-weight: bolder;
}

Right now I'm just working with Chrome and Firefox. In Chrome the normal and bold variants work, but not the bolder variant (keeps the 'bold' one). In Firefox only the bold variant works as expected, in any other case the bolder variant is used (even for normal weight).
Is this a known issue or is there a better way to do this declaration?

like image 747
olanod Avatar asked Mar 11 '13 15:03

olanod


People also ask

What is font face in Word?

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 face and font family?

While a typeface is a set of design features for letters and other characters, a font is the variation in weight and size of a typeface. A font family is a group of related fonts.

What are the types of font face?

Typography Basics There are five basic classifications of typefaces: serif, sans serif, script, monospaced, and display. As a general rule, serif and sans serif typefaces are used for either body copy or headlines (including titles, logos, etc.), while script and display typefaces are only used for headlines.

What is font variant in CSS?

The font-variant CSS shorthand property allows you to set all the font variants for a font. You can also set the CSS Level 2 (Revision 1) values of font-variant , (that is, normal or small-caps ), by using the font shorthand.


2 Answers

There are 2 separate issues here:

  1. The use of font-weight keywords rather than numeric values.
  2. Support for IE8 (and earlier versions), if needed.

Keywords

The problem with using font-weight keywords appears to be that lighter and bolder are not absolute values like normal and bold (always 400 and 700, respectively), but are relative to the established boldness of the parent element (100 lighter or darker). It may not be possible to treat lighter and bolder as if they're absolute values.

As @HTMLDeveloper and @Christoph suggested, using numeric values rather than keywords is the easy solution to this, and may by itself be an adequate solution (if support for IE8 isn't needed).

@font-face {
  font-family: "santana";
  src: url("data:font/ttf;base64,AAEAAAALAI....") format('truetype');
  font-weight: 400;
  font-style: normal;
}
@font-face {
  font-family: "santana";
  src: url("data:font/ttf;base64,AAEAAAALAI....") format('truetype');
  font-weight: 700;
}
@font-face {
  font-family: "santana";
  src: url("data:font/ttf;base64,AAEAAAALAI....") format('truetype');
  font-weight: 900;    /* or whatever weight you need to use for "bolder" */
}

IE8 and earlier

Some browsers have display issues when multiple weights or styles are associated with the same font-family name.

Specific issues I'm aware of:   (there may be others)

  • When more than 1 weight is linked to a font-family name, IE8 has display issues.
  • When more than 4 weights or styles are linked to a font-family name, IE6/7/8 has display issues.

The solution is to use a unique font-family name for each font variation:

@font-face {
  font-family: "santana";
  src: url("data:font/ttf;base64,AAEAAAALAI....") format('truetype');
}
@font-face {
  font-family: "santana-bold";
  src: url("data:font/ttf;base64,AAEAAAALAI....") format('truetype');
}
@font-face {
  font-family: "santana-bolder";
  src: url("data:font/ttf;base64,AAEAAAALAI....") format('truetype');
}

This approach is commonly used by font services like Typekit. If support for a wide variety of browsers is needed (or at least, IE8 in particular), this could be considered one of the prices you have to pay when embedding fonts.

like image 54
Matt Coughlin Avatar answered Oct 07 '22 17:10

Matt Coughlin


In font-face single font the quotes for font family name is not needed. you should remove and run it will works fine. font-family: santana; font-weight: 900; do not need for single font, it needs only multiple fonts. instead of bolder use numerical value it should works fine.

like image 23
Web Designer cum Promoter Avatar answered Oct 07 '22 18:10

Web Designer cum Promoter