Using #font-face causes different characters to display in Safari - css

I've added a font face to my website using this code:
#font-face {
font-family: 'ChunkFive-Roman';
src: url('/css/font/ChunkFive-Roman.eot') format('eot'),
url('/css/font/ChunkFive-Roman.otf') format('opentype'),
url('/css/font/ChunkFive-Roman.woff') format('woff'),
url('/css/font/ChunkFive-Roman.ttf') format('truetype'),
url('/css/font/ChunkFive-Roman.svg#ChunkFive-Roman') format('svg');
}
This works okay on XP in all browsers except Safari:
Why is that, and more importantly, how can I fix this?
These fonts are available here.

found an article on this issue: WEBKIT (SAFARI 3.1) AND THE CSS #FONT-FACE DECLARATION
The CSS spec section for #font-face is very specific - typefaces are to be selected based on a wide array of criteria placed in the #font-face declaration block itself. Various textual CSS attributes may be defined within the #font-face declaration, and then they will be checked when the typeface is referred to later in the CSS. For instance, if I have two #font-face declarations for the Diavlo family - one for regular text, and one for a heavier weighted version of the typeface - then I later utilize Diavlo in a font-family: attribute, it should refer to the basic Diavlo font defined in the first #font-face. However, if I were to do the same, but also specify a heavy font-weight:, then it should use the heavier version of Diavlo. To place this example in code:
#font-face {
font-family: 'Diavlo';
src: url(./Diavlo/Diavlo_Book.otf) format("opentype");
}
#font-face {
font-family: 'Diavlo';
font-weight: 900;
src: url(./Diavlo/Diavlo_Black.otf) format("opentype");
}
h1, h2, h3, h4, h5, h6 {
font-family: 'Diavlo';
font-weight: 900;
}
div#content {
font-family: 'Diavlo';
}
As you can see, my headings should use the typeface defined in Diavlo_Black.otf, while my body content should use Diavlo_Book.otf. However, in WebKit, this doesn’t work - it completely ignores any attribute except font-family: and src: in a #font-face declaration! Completely ignores them! Not only that - not only that - it disregards all but the last #font-face for a given font-family: attribute string!
The implication here is that, to make #font-face work as it is currently implemented in WebKit (and thus, Safari 3.1), I have to declare completely imaginary, non-existent type families to satisfy WebKit alone. Here’s the method I have used in the places I current implement #font-face:
#font-face {
font-family: 'Diavlo Book';
src: url(./Diavlo/Diavlo_Book.otf) format("opentype");
}
#font-face {
font-family: 'Diavlo Black';
src: url(./Diavlo/Diavlo_Black.otf) format("opentype");
}
h1, h2, h3, h4, h5, h6 {
font-family: 'Diavlo Black';
}
div#content {
font-family: 'Diavlo Book';
}

Related

Can't get font face to work on wordpress

I'm going mad as I had my website working with custom web fonts and now suddenly it just stopped working.
I got the web font kit from Font Squirrel and I'm using my local WP site to test it.
I pasted the font kit at wp-content/themes/twentyfifteen/fonts/
Here is the content from my style.css from the theme folder
#font-face {
font-family: 'quicksandregular';
src: url('/fonts/quicksand-regular-webfont.woff2') format('woff2'),
url('/fonts/quicksand-regular-webfont.woff') format('woff');
font-weight: normal;
font-style: normal;
}
h {
font-family: 'quicksandregular' !important;
}
And nothing happens in the web page. I can't see my custom font, which is Bebas Neue.
Any help will be much appreciated.
Regards.
Did you mean to paste the font family of "quicksand"? Regardless, this should be a good template to import new fontfaces.
#font-face {
font-family: 'quicksandregular';
src: url('/htdocs/www/wp-content/themes/twentyfifteen/fonts/quicksand-regular-webfont.woff2') format('woff2'),
url('/htdocs/www/wp-content/themes/twentyfifteen/fonts/quicksand-regular-webfont.woff') format('woff');
font-weight: normal;
font-style: normal;
}
Then when you call your font, it will need to be done in a valid selector with a valid name, ie:
/* Style all Headlines */
h1, h2, h3, h4, h5, h6{
font-family: "quicksandregular";
}
You should also be using a fall back font stack like so:
/* Style all Headlines */
h1, h2, h3, h4, h5, h6{
font-family: "quicksandregular", Arial, Helvetica, sans-serif;
}

Font Face Selectors with weight and style properties - browser ignores all but last selector

I am using multiple web fonts of the same family to avoid browsers from rendering in faux-bold and faux-italics. When declaring selectors, I set the same name for all font-family properties and am using font-weight and font-style to differentiate.
Here's an example I'm using for Exo.
#font-face {
font-family: "exo";
src: url("../fonts/exo/exo-regular.eot");
src: url("../fonts/exo/exo-regular.eot?#iefix") format("embedded-opentype"),
url("../fonts/exo/exo-regular.woff2") format("woff2"),
url("../fonts/exo/exo-regular.woff") format("woff"),
url("../fonts/exo/exo-regular.ttf") format("truetype"),
url("../fonts/exo/exo-regular.svg#exo") format("svg");
font-weight: "normal";
font-style: "normal";
}
#font-face {
font-family: "exo";
src: url("../fonts/exo/exo-bold.eot");
src: url("../fonts/exo/exo-bold.eot?#iefix") format("embedded-opentype"),
url("../fonts/exo/exo-bold.woff2") format("woff2"),
url("../fonts/exo/exo-bold.woff") format("woff"),
url("../fonts/exo/exo-bold.ttf") format("truetype"),
url("../fonts/exo/exo-bold.svg#exo") format("svg");
font-weight: "bold";
font-style: "normal";
}
p {
font-family: "exo", sans-serif;
}
I have confirmed that a paragraph tag is not inheriting font-weight from another selector.
From the above CSS I am expecting a <p/> tag to have a normal font weight. Instead, all instances of <p/> are bold. When checking the browser inspector, the font-weight, it reads as 'normal.'
I am also using Roboto with web fonts for all things normal, bold, italics, and bold-italics. Whatever is the last #font-face selector listed is what gets used be default.
I've seen different ways to implement this approach using different font-family names (e.g. font-family: "exo-bold"), but I shouldn't have to do that. My objective is to:
Use multiple web font files that represent the font in different states (e.g. exo-regular.woff, exo-bold.woff).
Use the same font-family name for all weight and style variants of the same font.
Include font-weight and font-style properties to identify those variants.
Set weight and style using other CSS or markup like <strong>.
It seems like I've done this before and it's worked. Can anyone spot an error in my approach?
No quotes should be used in your font-weight and font-style rules. This will work:
#font-face {
font-family: "exo";
/* files for normal weight */
font-weight: normal;
font-style: normal;
}
#font-face {
font-family: "exo";
/* files for bold weight */
font-weight: bold;
font-style: normal;
}
Actually, in CSS you only need quotes when you have spaces or other reserved characters in your font names or file names. So this should work:
<!-- language: lang-css -->
#font-face {
font-family: exo;
src: url(../fonts/exo/exo-regular.eot);
src: url(../fonts/exo/exo-regular.eot?#iefix) format(embedded-opentype),
url(../fonts/exo/exo-regular.woff2) format(woff2),
url(../fonts/exo/exo-regular.woff) format(woff),
url(../fonts/exo/exo-regular.ttf) format(truetype),
url(../fonts/exo/exo-regular.svg#exo) format(svg);
font-weight: normal;
font-style: normal;
}
#font-face {
font-family: exo;
src: url(../fonts/exo/exo-bold.eot);
src: url(../fonts/exo/exo-bold.eot?#iefix) format(embedded-opentype),
url(../fonts/exo/exo-bold.woff2) format(woff2),
url(../fonts/exo/exo-bold.woff) format(woff),
url(../fonts/exo/exo-bold.ttf) format(truetype),
url(../fonts/exo/exo-bold.svg#exo) format(svg);
font-weight: bold;
font-style: normal;
}
p {
font-family: exo, sans-serif;
}
I personally only use quotes in CSS when it doesn't work without.
But you never quote normal CSS terms, as they'll stop working.

Change default font type

I want to change the default font used in my application. I have installed #font-face but not all of the elements were changed. Is it possible to use element 'body' and put font-family I want there? It'd be like :
body {
font-family: 'champagne'; }
I've put this :
#font-face {
font-family: Champagne;
src: url(css/font/Champagne_Limousines.TTF); }
If you are already using font-family on body like this
body {
font-family: 'Font Name';
}
It should apply to all elements if its not applying means font-family properties already defined for other elements as well. for example
p{
font-family: Arial;
}
for that you can use * selector like this
*{
font-family: 'Font Name' !important;
}
which will override all other elements, also you have to use web fonts for it and all other formats as well to support all browsers
EOT,WOFF,SVG & TTF
your Font face should look like this
#font-face
{
font-family: 'FontName';
src: url('FontName.eot');
src: url('FontName.eot?#iefix') format('embedded-opentype'),
url('FontName.woff') format('woff'),
url('FontName.ttf') format('truetype'),
url('FontName.svg') format('svg');
font-weight: normal;
font-style: normal;
}

#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?
There are 2 separate issues here:
The use of font-weight keywords rather than numeric values.
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.
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.

#font-face not working even after trying everything I could think of

I really need help with #font-face code.
IT doesn't seem to see my font file.
I tried changing the path to anything I could think of, made new folders, renamed existing ones, put the font file in my root etc.
I'm testing in Firefox and Chrome.
Here are the codes that I tried in my CSS:
src: url(http://thefalljourneyindia.iblogger.org/wp-content/themes/thefalltheme/images/Univers.ttf);
src: url(thefalljourneyindia.iblogger.org/wp-content/themes/thefalltheme/images/Univers.ttf);
src: url(http://www.thefalljourneyindia.iblogger.org/wp-content/themes/thefalltheme/images/Univers.ttf);
src: url(www.thefalljourneyindia.iblogger.org/wp-content/themes/thefalltheme/images/Univers.ttf);
src: url(/wp-content/themes/thefalltheme/images/Univers.ttf);
src: url(../wp-content/themes/thefalltheme/images/Univers.ttf);
src: url(wp-content/themes/thefalltheme/images/Univers.ttf);
src: url(/thefalltheme/images/Univers.ttf);
src: url(../thefalltheme/images/Univers.ttf);
src: url(thefalltheme/images/Univers.ttf);
src: url(/images/Univers.ttf);
src: url(../images/Univers.ttf);
src: url(images/Univers.ttf);
src: url(www.thefalljourneyindia.iblogger.org/Univers.ttf);
src: url(/Univers.ttf);
src: url(Univers.ttf);
src: url(../Univers.ttf);
Can you find out where I should put the font file or what to change in my CSS to get it to work?
(I also checked the similar questions here and elsewhere on the net and tried using this website to no avail.)
Thanks!
UPDATE:
bozdoz's suggestion doesn't work.
I used FontSquirrel to get the fonts.
This is the CSS:
#font-face {
font-family: 'lane';
src: url('http://thefalljourneyindia.iblogger.org/wp-content/themes/thefalltheme/images/univers-webfont.eot');
src: url('thttp://thefalljourneyindia.iblogger.org/wp-content/themes/thefalltheme/images/univers-webfont.eot?#iefix') format('embedded-opentype'),
url('http://thefalljourneyindia.iblogger.org/wp-content/themes/thefalltheme/images/univers-webfont.woff') format('woff'),
url('http://thefalljourneyindia.iblogger.org/wp-content/themes/thefalltheme/images/univers-webfont.ttf') format('truetype'),
url('http://thefalljourneyindia.iblogger.org/wp-content/themes/thefalltheme/images/univers-webfont.svg#LaneHumouresqueRegular') format('svg');
font-weight: normal;
font-style: normal;
}
h1{ font-size: 110px;
font-family: 'lane', georgia, serif;
color: #000000;
}
I used the name 'lane' just because bozdoz had it.
All of the fonts are here:
http://thefalljourneyindia.iblogger.org/wp-content/themes/thefalltheme/images/
and these are their names:
univers-webfont.eot, univers-webfont.woof, univers-webfont.ttf, univers-webfont.svg
Are you using it correctly? Here is the format for #font-face. Notice the number of files. You can use Font Squirrel to create all of the necessary fonts for cross-browser compatibility. Also, it looks like you're using WordPress. I believe you have to use absolute paths (i.e. the first one in your list) in CSS on WordPress. Hope this helps.
<style>
#font-face {
font-family: 'lane';
src: url('type/lanehum-webfont.eot');
src: url('type/lanehum-webfont.eot?#iefix') format('embedded-opentype'),
url('type/lanehum-webfont.woff') format('woff'),
url('type/lanehum-webfont.ttf') format('truetype'),
url('type/lanehum-webfont.svg#LaneHumouresqueRegular') format('svg');
font-weight: normal;
font-style: normal;
}
.font { font-family:"lane", arial, serif; }
</style>
You want to do something like this:
#font-face { font-family: Delicious; src: url('Delicious-Roman.otf'); }
The font definition file must be relative to your css file. So if your css is at:
/Content/css/main.css
Then your font must be located in the same folder. If you specify
#font-face { font-family: Delicious; src: url('fonts/Delicious-Roman.otf'); }
Then your font definition would be at
/Content/css/fonts/Delicious-Roman.otf
You might want to verify that your server is not blocking your fonts from being downloaded. Try the URL and see if you get a 404 or 403 at the given url.
You should try fontSuirrel's generator, their scripts have been vastly tested and compliant with many browsers. Choose advanced settings when generating your fonts. Certain browsers may not have the ability to use ttf as a font so they provide you with eot woff and ttf
My suggestions from the comments as an answer:
Try with quotes:
url("Univers.ttf");
Check you have font-family or otherwise you cannot use your font in your code:
font-family: "MyFontName";
Your custom font family you would use in css like:
p { font-family: "MyFontName", Arial, sans-serif; }
First of all, thank you all for your great, great help!
There was no problem with the #font-face code.
The problem was with my overall CSS.
You see, my CSS was written like this:
/*
Info
*/
#media screen {
* {
margin: 0px;
padding: 0px;
}
html { background: black url(images/bg.jpg); }
body { font: 14px/1.4 Georgia, serif; }
article, aside, figure, footer, header, nav, section { display: block; }
#font-face {
font-family: 'lane';
src: url('http://thefalljourneyindia.iblogger.org/wp-content/themes/thefalltheme/images/univers-webfont.eot');
src: url('thttp://thefalljourneyindia.iblogger.org/wp-content/themes/thefalltheme/images/univers-webfont.eot?#iefix') format('embedded-opentype'),
url('http://thefalljourneyindia.iblogger.org/wp-content/themes/thefalltheme/images/univers-webfont.woff') format('woff'),
url('http://thefalljourneyindia.iblogger.org/wp-content/themes/thefalltheme/images/univers-webfont.ttf') format('truetype'),
url('http://thefalljourneyindia.iblogger.org/wp-content/themes/thefalltheme/images/univers-webfont.svg#LaneHumouresqueRegular') format('svg');
font-weight: normal;
font-style: normal;
}
etc.
The problem was that #font-face wasn't seen because it was after #media screen!
After I put it in front of #media screen and after /* Info */ it worked flawlessly.
Also, seems like I can use absolute and relative paths when using Wordpress...
Once again, thank you all for all your help!

Resources