Add custom font css with #font-face NOT WORKING - html

I'm trying to load a custom font from [DaFont.com (CaviarDreams)][1], with #font-face in css. I use this: https://www.fontsquirrel.com/tools/webfont-generator and I get this in css:
/*! Generated by Font Squirrel (https://www.fontsquirrel.com) on July 13, 2018 */
#font-face {
font-family: 'caviar';
src: url('font/caviardreams-webfont.eot');
src: url('font/caviardreams-webfont.eot?#iefix') format('embedded-opentype'),
src: url('font/caviardreams-webfont.woff2') format('woff2'),
src: url('font/caviardreams-webfont.woff') format('woff'),
src: url('font/caviardreams-webfont.svg#caviar_dreamsregular') format('svg');
font-weight: normal;
font-style: normal;
}
p {
font-size:40px;
font-family:caviar;
}
<!DOCTYPE html>
<html lang="fr-FR">
<head>
<title>test</title>
<link rel="stylesheet" href="styles.css">
<meta charset="UTF-8">
</head>
<body>
<p>test<p>
</body>
</html>
But it don't work!
(edited)
Can you help me?

So after testing it on my site I have found a few issues:
Your css class for p is not correct.
In the font url list you have comma separeeted insted of semicolumn
I have tried the same steps as you have, and get only woff and woff2 files. (So you need to remove the eot,svg paths from css)
My code fo one example:
<style>
#font-face {
font-family: 'caviar';
src: url('font/caviardreams-webfont.woff2') format('woff2');
src: url('font/caviardreams-webfont.woff') format('woff');
font-weight: normal;
font-style: normal;
}
p{
font-family:caviar;
font-weight:normal;
font-style:normal;
}
</style>
<div>
<p>Test</p>
</div>
Hope this helps,

Related

Different font on strong elements for Internet Explorer 11 and Safari on iOS 9

I have a web app with two fonts, Amatic SC for h1 and h2 and Open Sans for the rest. The webpage displays strong text fine on most browsers:
For Safari on iOS 9 (tested on iPhone 4S) and Internet Explorer 11 on Windows 8.1 (tested on LambdaTest), the strong elements use the font from the h1 and h2 elements:
The relevant CSS for these elements is:
#font-face {
font-family: 'Amatic SC';
font-style: normal;
font-weight: 400;
src: url(/fonts/amatic-sc-v13-latin-regular.woff2) format('woff2'), url(/fonts/amatic-sc-v13-latin-regular.woff) format('woff'); }
#font-face {
font-family: 'Amatic SC';
font-style: bold;
font-weight: 700;
src: url(/fonts/amatic-sc-v13-latin-700.woff2) format('woff2'), url(/fonts/amatic-sc-v13-latin-700.woff) format('woff'); }
#font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: 400;
src: url(/fonts/open-sans-v17-latin-regular.woff2) format('woff2'), url(/fonts/open-sans-v17-latin-regular.woff) format('woff');
}
#font-face {
font-family: 'Open Sans';
font-style: bold;
font-weight: 700;
src: url(/fonts/open-sans-v17-latin-700.woff2) format('woff2'), url(/fonts/amatic-sc-v13-latin-regular.woff) format('woff');
}
body {
font-family: 'Open Sans', sans-serif;
}
h1, h2 {
margin: 0.5rem 0 0.5rem 0;
text-align: left;
font-family: Amatic SC, cursive;
font-weight: bold;
}
The website is at www.emotionathletes.org if you want to further inspect.
What is the reason for the use of a different font on iOS Safari and Internet Explorer?
Minimal reproducible example
Following the comment, I narrowed the issue to the loading of the fonts. If I load them in the head of the HTML, linked to Google Fonts, then the page displays well. If I load them locally in the CSS with #font-face from a woff or woff2 file, then the strong elements display with a different font on iOS 9 on iPhone 4S and on Internet Explorer 11 on Windows 8.1. The order of loading the fonts in the CSS does not change the result.
A minimal reproducible example has HTML file strong.html:
<!DOCTYPE html>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"><meta charset="utf-8"><meta name="viewport" content="width=device-width, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
<link rel="stylesheet" type="text/css" href="strong.css">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Open+Sans&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Amatic+SC&display=swap" rel="stylesheet">
</head>
<body>
<h2>Summary</h2>
<p>The Bulgy series, whose first season is "Emotion Athletes", has the following purposes:</p>
<ul>
<li>
transform the <strong>difficulties</strong> of the <strong>pandemic</strong> into <strong>opportunities</strong> for children to <strong>recognise what they are feeling, understand the reason, and use their emotions</strong>;
</li>
</ul>
</body>
</html>
and CSS file strong.css:
/*
Amatic SC and Open Sans are Google Fonts:
https://fonts.google.com/specimen/Amatic+SC?sidebar.open=true&selection.family=Open+Sans#about
https://fonts.google.com/specimen/Open+Sans?sidebar.open=true&selection.family=Open+Sans#about
*/
/* comment these #font-faces for the page to work properly. */
#font-face {
font-family: 'Amatic SC';
font-style: normal;
font-weight: 400;
src: url(/fonts/amatic-sc-v13-latin-regular.woff2) format('woff2'), url(/fonts/amatic-sc-v13-latin-regular.woff) format('woff'); }
#font-face {
font-family: 'Amatic SC';
font-style: bold;
font-weight: 700;
src: url(/fonts/amatic-sc-v13-latin-700.woff2) format('woff2'), url(/fonts/amatic-sc-v13-latin-700.woff) format('woff'); }
#font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: 400;
src: url(/fonts/open-sans-v17-latin-regular.woff2) format('woff2'), url(/fonts/open-sans-v17-latin-regular.woff) format('woff');
}
#font-face {
font-family: 'Open Sans';
font-style: bold;
font-weight: 700;
src: url(/fonts/open-sans-v17-latin-700.woff2) format('woff2'), url(/fonts/amatic-sc-v13-latin-regular.woff) format('woff');
}
body {
font-family: 'Open Sans', sans-serif;
}
h1, h2 {
font-family: 'Amatic SC', cursive;
}
I put a live version at www.emotionathletes.org/strong.html, with CSS file at www.emotionathletes.org/strong.css.
For my own reasons, I prefer to serve the font files from my server than query them from Google Fonts. How can I serve the font files locally and still display them properly on Safari and Internet Explorer?
The issue was in the code, which I found today as I was changing the main font:
For Open Sans at 700, the woff filepath was:
/fonts/amatic-sc-v13-latin-regular.woff
and should have been:
/fonts/open-sans-v17-latin-700.woff
Older browsers use woff and not woff2, and so they were doing exactly as they were told. I now fixed the issue.
Moral of the story: if using local fonts for performance, make sure to do the right wiring of CSS to filepaths.

Setting font-family to 'Goudy Trajan Regular' in my style sheet not working

I am using #font-face to define a font family in my CSS style sheet. When I then try to set the font family attribute, I am not able to get the new font to display on my HTML page.
#font-face {
font-family: 'Goudy Trajan Regular';
font-style: normal;
font-weight: 400;
src: local('Goudy Trajan Regular'), local('GoudyTrajan-Regular'),
url(http://allfont.net/cache/fonts/goudy-trajan-regular_9c60d369eeef3d3ea1e3ddaa07f3e15f.woff) format('woff'),
url(http://allfont.net/cache/fonts/goudy-trajan-regular_9c60d369eeef3d3ea1e3ddaa07f3e15f.ttf) format('truetype');
}
html, body
{
height: 95%;
width: 90%;
font-family: 'Goudy Trajan Regular', arial;
}
Update: I've stripped everything out and it still is not working. Here is my complete CSS -
#font-face {
font-family: 'Goudy Trajan Regular';
font-style: normal;
font-weight: 400;
src: local('☺'),
url(http://allfont.net/cache/fonts/goudy-trajan-regular_9c60d369eeef3d3ea1e3ddaa07f3e15f.woff) format('woff'),
url(http://allfont.net/cache/fonts/goudy-trajan-regular_9c60d369eeef3d3ea1e3ddaa07f3e15f.ttf) format('truetype');
}
body
{
font-family: 'Goudy Trajan Regular', arial;
}
Here is my complete HTML -
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="css/style2.css">
</head>
<body>
<h1>TESTING A NEW FONT</h1>
</body>
</html>

Including google font in my project

I included Montserrat-Regular in my project. But its not detecting and font style is not changing.
In my index.html:
I included the fonts URL too.
<link href = "https://fonts.googleapis.com/css?family=Montserrat:400,700" rel='stylesheet' type='text/css'>
css:
#import url(http://fonts.googleapis.com/css?family=Montserrat:400,700);
#font-face {
font-family: 'Montserrat';
font-style: normal;
font-weight: 400;
src: local('Montserrat Regular'), local('Montserrat-Regular'), url(https://fonts.gstatic.com/s/montserrat/v10/SKK6Nusyv8QPNMtI4j9J2yEAvth_LlrfE80CYdSH47w.woff2) format('woff2');
unicode-range: U+0102-0103, U+1EA0-1EF9, U+20AB;
}
You only have to put the link in your HTML file :
<link href = "https://fonts.googleapis.com/css?family=Montserrat:400,700" rel='stylesheet' type='text/css'>
and then use it on every element you want in your CSS file:
p {
font-family: 'Montserrat';
}
Check this fiddle for a better example: https://jsfiddle.net/vf7q1gjy/1/
Set the font family in your CSS file:
body { font-family: 'Montserrat', sans-serif; }

Can't make any different fonts show up on website with #font-face or google fonts

I'm new to web dev so please excuse the ignorance...
I'm trying to put a custom font on my website. I've tried doing it with #font-face and google fonts but nothing seems to work.
I've (hopefully) linked the google font in the top of the HTML doc. Also linked the fonts.css containing the 'shewalks' font. The CSS file shows how I tried to link the fonts using #font-face.
WTH am I doing wrong?
Folder Structure
css:
#font-face {
font-family: 'shewalks';
src: url('./fonts/she_always_walks_alone_demo-webfont.ttf');
src: url('./fonts/she_always_walks_alone_demo-webfont.woff');
src: url('./fonts/she_always_walks_alone_demo-webfont.svg');
src: url('./fonts/she_always_walks_alone_demo-webfont.eot');
src: url('./fonts/she_always_walks_alone_demo-webfont.woff2');
}
a {
font-family:'pacifico',verdana,arial;
}
h2 {
font-family: 'Pacifico', cursive;
}
body {
text-align: center;
font-family: 'shewalks';
}
header {
position: fixed;
background: #ffffff;
width: 100%;
z-index: 10;
position: fixed;
height: 300px;
}
html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link href='https://fonts.googleapis.com/css?family=Pacifico' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="fonts/fonts.css" />
<link href="style.css" rel="stylesheet" />
<title>Me and the Monster</title>
</head>
<body>
<div id="banner">
<h2>Me and the Monster</h2>
</div>
<div id="content">
<h2><div style="font-family: 'pacifico', serif;">This should be in 'pacifico' font.</div></h2>
<p>Content goes here </p>
<p>Content goes here </p>
</div>
Thanks so much for any and all help!
If you go the Google route, your code should look like:
HTML:
<link href='https://fonts.googleapis.com/css?family=Pacifico' rel='stylesheet' type='text/css'>
CSS:
body {
font-family: 'Pacifico', cursive;
}
If you go the '#import' route, and are hosting the fonts on your own server, your code should look like:
CSS:
#font-face {
font-family:"She Always Walk Alone Demo";
src:url("/fonts/She_Always_Walks_Alone_Demo.eot?") format("eot"),
url("/fonts/She_Always_Walks_Alone_Demo.woff") format("woff"),
url("/fonts/She_Always_Walks_Alone_Demo.ttf") format("truetype"),
url("/fonts/She_Always_Walks_Alone_Demo.svg#SheAlwaysWalkAloneDemo") format("svg");
font-weight:normal;
font-style:normal;
}
body {
font-family: 'She Always Walk Alone Demo', cursive;
}
In your font.css :
src: url('./fonts/she_always_walks_alone_demo-webfont.ttf');
Url is not about your server path, but relative your domain from font.css.
So, it should work:
src: url('fonts/she_always_walks_alone_demo-webfont.ttf');
You should also include the format on your src like below:
#font-face {
font-family: 'MyWebFont';
src: url('webfont.eot'); /* IE9 Compat Modes */
src: url('webfont.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('webfont.woff2') format('woff2'), /* Super Modern Browsers */
url('webfont.woff') format('woff'), /* Pretty Modern Browsers */
url('webfont.ttf') format('truetype'), /* Safari, Android, iOS */
url('webfont.svg#svgFontName') format('svg'); /* Legacy iOS */
}
Also, fix in your index.html:
<link href='https://fonts.googleapis.com/css?family=Pacifico' />

css not able to load font in correct way

i have to load font into css from folder, but it is not working
html
is :
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<style>
#font-face { font-family: 'HelveticaWorld'; font-style: normal; font-weight: bold; src: URL("../Fonts/HelveticaWorld-Bold.ttf") format('ttf'); }
</style>
</head>
<body>
<div style="margin-bottom: 15px; font-weight: bold;font-family: HelveticaWorld"">Setup</div>
</body>
</html>
download physical html file ( zip)
Looking at the zip file, your font path and format are wrong. Try:
#font-face { font-family: 'HelveticaWorld'; font-style: normal; font-weight: bold; src: URL("font/HelveticaWorld-Bold.ttf") format('truetype'); }