Use Multiple Custom Fonts Using @Font-Face

Use multiple custom fonts using @font-face?

You simply add another @font-face rule:

@font-face {
font-family: CustomFont;
src: url('CustomFont.ttf');
}

@font-face {
font-family: CustomFont2;
src: url('CustomFont2.ttf');
}

If your second font still doesn't work, make sure you're spelling its typeface name and its file name correctly, your browser caches are behaving, your OS isn't messing around with a font of the same name, etc.

How do add multiple font-family to my style sheet using @font-face rule?

You can always add multiple @fontface in your css provided with the font-family name.

@font-face {
font-family: myFirstFont;
src: url(myFirstFont.woff);
font-weight: bold;
}

@font-face {
font-family: mySecondFont;
src: url(mySecondFont.woff);
font-weight: bold;
}

Use multiple @font-face rules in CSS

Note, you may also be interested in:

Custom web font not working in IE9

Which includes a more descriptive breakdown of the CSS you see below (and explains the tweaks that make it work better on IE6-9).


@font-face {
font-family: 'Bumble Bee';
src: url('bumblebee-webfont.eot');
src: local('☺'),
url('bumblebee-webfont.woff') format('woff'),
url('bumblebee-webfont.ttf') format('truetype'),
url('bumblebee-webfont.svg#webfontg8dbVmxj') format('svg');
}

@font-face {
font-family: 'GestaReFogular';
src: url('gestareg-webfont.eot');
src: local('☺'),
url('gestareg-webfont.woff') format('woff'),
url('gestareg-webfont.ttf') format('truetype'),
url('gestareg-webfont.svg#webfontg8dbVmxj') format('svg');
}

body {
background: #fff url(../images/body-bg-corporate.gif) repeat-x;
padding-bottom: 10px;
font-family: 'GestaRegular', Arial, Helvetica, sans-serif;
}

h1 {
font-family: "Bumble Bee", "Times New Roman", Georgia, Serif;
}

And your follow-up questions:

Q. I would like to use a font such as "Bumble bee," for example. How can I use @font-face to make that font available on the user's
computer?

Note that I don't know what the name of your Bumble Bee font or file is, so adjust accordingly, and that the font-face declaration should precede (come before) your use of it, as I've shown above.

Q. Can I still use the other @font-face typeface "GestaRegular" as well? Can I use both in the same stylesheet?

Just list them together as I've shown in my example. There is no reason you can't declare both. All that @font-face does is instruct the browser to download and make a font-family available. See: http://iliadraznin.com/2009/07/css3-font-face-multiple-weights

Multiple font-weights, one @font-face query

Actually there is a special flavor of @font-face that will permit just what you're asking.

Here's an example using the same font-family name with different styles and weights associated with different fonts:

@font-face {
font-family: "DroidSerif";
src: url("DroidSerif-Regular-webfont.ttf") format("truetype");
font-weight: normal;
font-style: normal;
}

@font-face {
font-family: "DroidSerif";
src: url("DroidSerif-Italic-webfont.ttf") format("truetype");
font-weight: normal;
font-style: italic;
}

@font-face {
font-family: "DroidSerif";
src: url("DroidSerif-Bold-webfont.ttf") format("truetype");
font-weight: bold;
font-style: normal;
}

@font-face {
font-family: "DroidSerif";
src: url("DroidSerif-BoldItalic-webfont.ttf") format("truetype");
font-weight: bold;
font-style: italic;
}

You can now specify font-weight:bold or font-style:italic to any element you like without having to specify the font-family or overriding font-weight and font-style.

body { font-family:"DroidSerif", Georgia, serif; }

h1 { font-weight:bold; }

em { font-style:italic; }

strong em {
font-weight:bold;
font-style:italic;
}

For a full overview of this feature and the standard use take a look at this article.


EXAMPLE PEN

How to add multiple font files for the same font?

The solution seems to be to add multiple @font-face rules, for example:

@font-face {
font-family: "DejaVu Sans";
src: url("fonts/DejaVuSans.ttf");
}
@font-face {
font-family: "DejaVu Sans";
src: url("fonts/DejaVuSans-Bold.ttf");
font-weight: bold;
}
@font-face {
font-family: "DejaVu Sans";
src: url("fonts/DejaVuSans-Oblique.ttf");
font-style: italic, oblique;
}
@font-face {
font-family: "DejaVu Sans";
src: url("fonts/DejaVuSans-BoldOblique.ttf");
font-weight: bold;
font-style: italic, oblique;
}

By the way, it would seem Google Chrome doesn't know about the format("ttf") argument, so you might want to skip that.

(This answer was correct for the CSS 2 specification. CSS3 only allows for one font-style rather than a comma-separated list.)

CSS @font-face does not work with multiple font weights

It appears there is an error in your CSS syntax, causing some of the fonts to not be loaded.

To fix the syntax, use a semicolon on the second line of the second src value.

@font-face {
font-family: 'CalibreWeb';
src: url('http://staging.parcelpet.com/wp-content/themes/oceanwp-child-theme/fonts/CalibreWeb-Regular.eot');
src: url('http://staging.parcelpet.com/wp-content/themes/oceanwp-child-theme/fonts/CalibreWeb-Regular.woff2') format('woff2'),
url('http://staging.parcelpet.com/wp-content/themes/oceanwp-child-theme/fonts/CalibreWeb-Regular.woff') format('woff');
font-weight: 400;
}
@font-face {
font-family: 'CalibreWeb';
src: url('http://staging.parcelpet.com/wp-content/themes/oceanwp-child-theme/fonts/CalibreWeb-Semibold.woff2');
src: url('http://staging.parcelpet.com/wp-content/themes/oceanwp-child-theme/fonts/CalibreWeb-Semibold.woff2') format('woff2'),
url('http://staging.parcelpet.com/wp-content/themes/oceanwp-child-theme/fonts/CalibreWeb-Semibold.woff') format('woff');
font-weight: 600;
}

How can I get multiple font weights working using @font-face

The problem is in the minified CSS. In WordPress, child themes need to have a Template header in style.css stylesheet. If this is missing, the theme will be "broken" and cause random issues.

/*
Theme Name: foo
Version: foo
Description: foo
Author: foo
Author URI: foo
template: foo
*/

How I found the answer: Having broken theme also prevented upload of featured image for posts and in solving that, the fonts were also resolved.

There is same way to import multiple custom font using javascript?

One way you can append style element to the head using javascript. Like below code snippet.

DEMO

let head = document.head || document.getElementsByTagName('head')[0],  style = document.createElement('style'),  fonts = {    "Animais-1.ttf": "http://ggt-des.br/styles/fontes/Animais-1.ttf",    "Animais-2.ttf": "http://ggt-des.br/styles/fontes/Animais-2.ttf",    "Animais.ttf": "http://ggt-des.br/styles/fontes/Animais.ttf",    "CPRM_Fontes.ttf": "http://ggt-des.br/styles/fontes/CPRM_Fontes.ttf",    "ESRI-Electric.ttf": "http://ggt-des.br/styles/fontes/ESRI-AMFM-Electric.ttf",    "ESRI-AMFM-Gas.ttf": "http://ggt-des.br/styles/fontes/ESRI-AMFM-Gas.ttf"  };
head.appendChild(style);
style.type = 'text/css';
let css = Object.entries(fonts).map(v => `@font-face { font-family: "${v[0].split('.')[0]}"; src: url(${v[1]}); font-weight: normal; font-style: normal;}`).join('');
if (style.styleSheet) { // This is required for IE8 and below. style.styleSheet.cssText = css;} else { style.appendChild(document.createTextNode(css));}
.one {  font-family: "Animais-1";}
.two { font-family: "Animais-2";}
.three { font-family: "Animais";}
.four { font-family: "CPRM_Fontes";}
.five { font-family: "ESRI-Electric";}
.six { font-family: "ESRI-AMFM-Gas";}
<div class="one">1</div><div class="two">2</div><div class="three">3</div><div class="four">4</div><div class="five">5</div><div class="six">6</div>

Using @font-face to implement custom fonts multiple times in web page

This is regular CSS. Please check a tutorial or similar. This does not apply to @font-face

<style>
.your-class {
font-family:"Simpletext";
}
</style>
<p class="your-class">Lorem Ipsum is simply dummy text </p>
<span class="your-class">Lorem Ipsum is simply dummy text</span>


Related Topics



Leave a reply



Submit