Hi I am trying to learn to use font-face to add a different font to my browser but I seem to be missing something in the code because the style is not applying. Here is my code:
<div id="logo">
<img src="img/header/THANATHOS.png" alt="Logo"/>
<p>a gamers community</p>
</div>
<style>
#font-face {
font-family: 'HarlowSolid';
src: url('Fonts/normal/HarlowSolid.eot'); /* IE9 Compat Modes */
src: url('Fonts/normal/HarlowSolid.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('Fonts/normal/HarlowSolid.woff') format('woff'), /* Modern Browsers */
url('Fonts/normal/HarlowSolid.ttf') format('truetype'), /* Safari, Android, iOS */
url('Fonts/normal/HarlowSolid.svg#svgFontName') format('svg'); /* Legacy iOS */
}
div#logo p{
font-family: HarlowSolid , Helvetica , sans-serif;
}
</style>
What am I doing wrong here?
Make sure you've either wrapped it in <style> /* Code Here */</style> tags, or put it in your style sheet.
Also check that the path to the file you've written that code in.
So if it's in /css/style.css and harlowSolid.woff is in root folder called fonts, then your code would need to be url('../Fonts/normal/HarlowSolid.woff')
Also check that the browser you're testing has support for font-face. Though with the conditionals you've included it should be unlikely to face a problem.
Just to confirm: The actual code you've posted is correct, so check your file exists/structured properly.
If you're using Chrome/Safari/FF, you can usually right click -> Inspect Element, look out for the red cog symbol in the bottom right corner which will denote coding/resource errors. (Click it to see the description of the problem.)
Are the second src right?
Have a look at http://www.w3schools.com/css3/css3_fonts.asp
#font-face {
font-family: 'HarlowSolid';
src: url('Fonts/normal/HarlowSolid.eot'); /* IE9 Compat Modes */
**src:** url('Fonts/normal/HarlowSolid.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('Fonts/normal/HarlowSolid.woff') format('woff'), /* Modern Browsers */
url('Fonts/normal/HarlowSolid.ttf') format('truetype'), /* Safari, Android, iOS */
url('Fonts/normal/HarlowSolid.svg#svgFontName') format('svg'); /* Legacy iOS */
}
Related
I have a website with a custom font (Gotham Book). All containers like this:
<span>TEXT IN GOTHAM </span>
Get height of 0 on Mac (Chrome and Safari, not on Chrome for Win). Same containers work fine with other fonts like Arial, or Roboto or whatever.
The font is in the CSS like this:
#font-face {
font-family: 'Gotham Book';
src: url("/assets/fonts/GothamBook.ttf")
}
Do i have to specify something else?
I think your font was not getting loaded for some reason and you need to debug that on mac (you should check your console for any error)
I would suggest to link all font file format which you have got with that font
, see below code for example
#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 */
}
I also suggest to add fallback font as if your font was not loaded it will take other font
font-family: 'MyWebFont', Arial, sans-serif;
This is my only CSS
#font-face {
font-family: 'thefont';
src: url('fonts/the-font.otf');
font-style: normal;
}
body {
font-family: 'thefont';
}
When I do a <button>Hi</button> the font ends up being -apple-system.
If I actually assign the font to button, it will make the font appear.
Does anyone know why it's not affecting the body and everything inside it?
In addition to the info below, to ensure your custom font is being taken into account for the button, you need to apply
button {
font-family : inherit;
font-size: 1em;
}
to all button elements.
You can inspect how they do it there:
http://purecss.io/buttons/
or there:
http://getbootstrap.com/css/#buttons
Also make sure that your font is exported in several different formats so that it is supported by all platforms.
You can use FontSquirrel Generator to export your font to all formats.
Your CSS should look a bit like that:
#font-face {
font-family: 'thefont';
src: url('the-font.eot'); /* IE9 Compat Modes */
src: url('the-font.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('the-font.woff2') format('woff2'), /* Super Modern Browsers */
url('the-font.woff') format('woff'), /* Pretty Modern Browsers */
url('the-font.ttf') format('truetype'), /* Safari, Android, iOS */
url('the-font.svg#svgFontName') format('svg'); /* Legacy iOS */
}
I tried to use face-font to add a couple of fonts to my page but unfortunately, even if I followed the instructions to make it compatible with browsers, it only works on Chrome and Safari and I can't work out why. I tried two different methods.
The first one looks like this:
#font-face {
font-family: 'robotoblack';
src: url('roboto-black-webfont.eot'); /* per IE 5-8 */
src: local('☺'), /* direttiva local per IE */
url('roboto-black-webfont.woff') format('woff'), /* Firefox 3.6+, Chrome 5.0+, IE 9.0+ */
url('roboto-black-webfont.ttf') format('truetype'); /* Opera, Safari */
}
#font-face {
font-family: 'robotomedium_italic';
src: url('roboto-mediumitalic-webfont.eot'); /* per IE 5-8 */
src: local('☺'), /* direttiva local per IE */
url('roboto-mediumitalic-webfont.woff') format('woff'), /* Firefox 3.6+, Chrome 5.0+, IE 9.0+ */
url('roboto-mediumitalic-webfont.ttf') format('truetype'); /* Opera, Safari */
}
and the second one like this:
#font-face {
font-family: 'robotoblack';
src: url('roboto-black-webfont.eot'); /* IE9 Compat Modes */
src: url('roboto-black-webfont.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('roboto-black-webfont.woff2') format('woff2'), /* Super Modern Browsers */
url('roboto-black-webfont.woff') format('woff'), /* Pretty Modern Browsers */
url('roboto-black-webfont.ttf') format('truetype'), /* Safari, Android, iOS */
url('roboto-black-webfont.svg#robotoblack') format('svg'); /* Legacy iOS */
}
#font-face {
font-family: 'robotomedium_italic';
src: url('roboto-mediumitalic-webfont.eot'); /* IE9 Compat Modes */
src: url('roboto-mediumitalic-webfont.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('roboto-mediumitalic-webfont.woff2') format('woff2'), /* Super Modern Browsers */
url('roboto-mediumitalic-webfont.woff') format('woff'), /* Pretty Modern Browsers */
url('roboto-mediumitalic-webfont.ttf') format('truetype'), /* Safari, Android, iOS */
url('roboto-mediumitalic-webfont.svg#robotomedium_italic') format('svg'); /* Legacy iOS */
}
Could you please tell me which of the two methods is the best one? Any suggestion to make it work on all browsers?
In case you want to see the example, it is available here:
enter link description here
I hope you can help! Thanks in advance
Cheers
Enrico
I see the answer, you're calling the font-family incorrectly. Make sure to use the #font-face font-family declaration. In this case, use 'robotoblack' instead of 'roboto-black'. And use quotes in your css when calling the fonts.
I also recommend calling #font-face first then call those font-families in the css after.
I'm trying to use a custom font (.oft) that I have uploaded into my font folder in my filesystem.
I've declared the font in CSS with the following:
#font-face {
font-family: '400'; /*a name to be used later*/
src: url('../font/400ml-Regular.otf'); /*URL to font*/
}
and called it with :
.intro .slogan {
text-align: center;
font-family: '400';
}
My index.html page is in the root folder (var/www/html) and the css and font are in /var/www/html/css and /var/www/html/font respectively (so i think the '..' in the src is correct). I've also added the following to .htaccess
AddType font/otf .otf
but i'm still not even able to see it loading in developer tools.
Does anyone have any advice?
To make #font-face work across different browsers and OP you need to make it like this
#font-face {
font-family: '400';
src: url('400ml-Regular.eot'); /* IE9 Compat Modes */
src: url('400ml-Regular.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('400ml-Regular.woff') format('woff'), /* Modern Browsers */
url('400ml-Regular.ttf') format('truetype'), /* Safari, Android, iOS */
url('400ml-Regular.svg#svgFontName') format('svg'); /* Legacy iOS */
}
Use a fontface generator to make different font formats. Try fontsquirel or simillar :)
This is the code I am using.
#font-face {
font-family:gotisch;
src:url('__cmsurl__/files/www/dscaslongotisch.ttf') format:('truetype');
}
h1{
font-family:gotisch;
}
the source is correct, the CMS automatically sets the url, but the font is not displayed in neither Chrome nor Firefox.
When I do use this code:
#font-face {
font-family:gotisch;
src:url('__cmsurl__/files/www/dscaslongotisch.ttf') format:('truetype');
}
#font-face {
font-family: gotisch_IE;
src:url('__cmsurl__/files/www/dscaslongotisch.eot');
}
h1{
font-family:gotisch, 'gotisch_IE';
}
it is working in IE, but still not in Firefox / Chrome
Firebug even shows me, that the font is loaded and I can change it to e.g. Verdana - but still, this one is just not displayed. I even tried fontsquirrel, but even then it did not display the font. Can anyone help me here?
Taken from here you can see that the fonts you provide (ttf and eot) are for IE, Safari, Android, iOS.
#font-face {
font-family: 'MyWebFont';
src: url('webfont.eot'); /* IE9 Compat Modes */
src: url('webfont.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('webfont.woff') format('woff'), /* Modern Browsers */
url('webfont.ttf') format('truetype'), /* Safari, Android, iOS */
url('webfont.svg#svgFontName') format('svg'); /* Legacy iOS */
}
Convert the font to woff and include it like below if you want it to work in Firefox and Chrome.
#font-face {
font-family: 'gotisch';
src: url('path_to/gotisch.eot'); /* IE9 Compat Modes */
src: url('path_to/gotisch.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('path_to/gotisch.woff') format('woff'), /* Modern Browsers */
url('path_to/gotisch.ttf') format('truetype'), /* Safari, Android, iOS */
}
Then use it like this
selector {
font-family: 'gotisch';
}