Using #fontface fonts load italic - css

I have css like so:
#font-face {
font-family: 'alegreya';
src:url('fonts/AlegreyaBold.ttf');
font-weight:normal;
font-style: normal;
}
#font-face {
font-family: 'alegreya';
src:url('fonts/AlegreyaBoldItalic.ttf');
font-weight:normal;
font-style: italic, oblique;
}
#font-face {
font-family: 'alegreya';
src:url('fonts/AlegreyaBlack.ttf');
font-weight:bold;
font-style: normal;
}
#font-face {
font-family: 'alegreya';
src:url('fonts/AlegreyaBlackItalic.ttf');
font-weight:bold;
font-style: italic, oblique;
}
And a rule for my class like this:
.font-alegreya {
font-family:alegreya;
}
And finally HTML:
<li class="font-alegreya" data-styles="bold, italic, extrabold">
Alegreya - Some sample words.
</li>
Now, I've read here on metaltoad and other places on SO that using a single font-family is the preferred way to utilize custom fonts and that you have to put bold-italic last.
The Problem is that the font is displayed italic. By using font-weight:normal in the css class, I get normal display weight, but font-style:normal doesn't clear the italics. This makes sense, since under (-webkit) "developer tools" in the "resources" tab, I only see the black-italic font loaded (second in my CSS file). The font is installed on my computer, but I renamed the file on the server.
I've observed this in opera (webkit) and IE11, so it's my code.
Edit: As mentioned in the comments, I had bold and black inverted. That accounts for the bold. But italic is still an issue.

As David Stone's answer on the authoritative answer to #fontface questions states, this spec says that oblique, italic IS valid.
As he stated, FF 3.6 doesn't like the two values. Buried in the comments there are more reports of two-values not working.
On digging into the webkit bug reports, I discovered that the value for font-style as prescribed by the spec changed from CSS2 to CSS3. According the later css3 spec, only one value is allowed for the font-style property, rather than a comma-separated list.
So nowdays, if you pass in a comma-separated list, the rendering engine says "that's not a valid font-style. They must have meant normal." And overrides your previous normal declaration.
tl;dr: If font face is rendering all italic fonts:
font-style: italic, oblique;
should be
font-style: italic;

Related

Is it possible to make font-weight: bold equal to 500 instead of 700?

I've just been playing with Google Fonts and found the Fira Sans font. It's nice but I don't like the Bold (700) style, it's too bold for my liking. However, if I select the Medium (500) style the browser doesn't use it for anything set to font-weight: bold (e.g. <strong>). Instead it uses some kind of faux bold that looks blurry.
I can go through my stylesheet and set every occurrence of bold to 500. I could also use Sass to set a variable like $bold-weight: 500; which helps if I decide to change the font later.
That's a bit of a pain though, plus bold is also the default for many browser styles (e.g. <strong>, <th>) so I have to make sure I catch every possible occurrence of that too. And there may be external scripts/styles I don't control.
Is there a way to make all occurrences of bold use weight 500?
Yes there is,
When you choose to quick use a google font, you are provided with a link to include into the header, Open the link into your web browser and you would be served with a css file with lots of
/* cyrillic-ext */
#font-face {
font-family: 'Roboto';
font-style: italic;
font-weight: 400;
src: local('Roboto Italic'), local('Roboto-Italic'), url(https://fonts.gstatic.com/s/roboto/v15/WxrXJa0C3KdtC7lMafG4dRTbgVql8nDJpwnrE27mub0.woff2) format('woff2');
unicode-range: U+0460-052F, U+20B4, U+2DE0-2DFF, U+A640-A69F;
}
As you can see the font-style: italic and the font-weight: 400 is linked with some specific font (Roboto Italic here) within the #font-face tag, meaning whenever you use font-weight: italic with font-weight: 400 (or normal), it refers to the font described within the src attribute.
Now, if you want to make all the font-weight: bold in your css use this font face, just change the 400 in above font-style to bold and you are done.
Or you can make a duplicate of the complete #font-face{..} and use another font-style into it.
Also, you can use different fonts here as well. Make sure to keep only one font-style or font-weight tag within a #font-face.
This example here uses google fonts, you can use the same technique for self-hosted fonts.

textarea fallback in IE

I'm using a icon font created from icomoon.io. It has a small limited set of characters that are associated with a set of Unicode characters. I need these icons to display when those specific characters are input into a textarea. When any other character is input though I want it to fallback to Tahoma. My CSS looks like this.
#font-face {
font-family: 'icomoon';
src:url('fonts/icomoon.eot');
src:url('fonts/icomoon.eot?#iefix') format('embedded-opentype'),
url('fonts/icomoon.woff') format('woff'),
url('fonts/icomoon.ttf') format('truetype'),
url('fonts/icomoon.svg#icomoon') format('svg');
unicode-range: U+2600-2750;
font-weight: normal;
font-style: normal;
}
body {
font-family: Tahoma, icomoon;
}
textarea {
font-family: Tahoma, icomoon;
}
This works fine in Chrome and Firefox. Regular characters show up in Tahoma and my special characters will show up in my icon font. It works in the body of my document and also in my textarea.
In IE in the body everything works the same. Regular characters in Tahoma, special characters in icon font. In the textarea however IE is falling back to another set of symbols instead of my icon font. The non-special characters show up in Tahoma.
If I reverse the fonts in the font family...
textarea {
font-family: icomoon, Tahoma;
}
Now my icon font shows up but IE falls back to a different font other than Tahoma.
Tahoma is just an example by the way, using generic san-serif does the same thing.
Is this just a IE bug or is there a way to fix this behavior, or is there something I'm missing?
Update
I simplified even more and made this JSFiddle. If you run it in Chrome and then IE you should see the issue.
http://jsfiddle.net/sx7B4/
As your simplified example shows, this is a bug in IE (at least in IE 10 in all modes) and does not depend on #font-face fonts. A further simplification:
<!DOCTYPE html>
<title>textarea fallback in IE</title>
<style>
body {
font-family: Georgia, Courier New; }
textarea {
font-size: 100%;
font-family: Georgia, Courier New; }
</style>
Hello world ↕<br>
<textarea>Hello world ↕</textarea>
Since Georgia does not contain U+2195 (↕) but Courier New does, we should get the Courier New glyph in both cases. What we get instead in the textarea on IE seems to be from MS Gothic or some similar font.
So apparently IE uses only the first existing font family name in the font-family property list for textarea, and for characters not found in it, it uses its own fallback mechanism.
Workaround: instead of textarea, use div (or other element) with the contenteditable attribute and (if the textarea is part of a form to be submitted) copy the content of that element into a hidden field of the form. (This is complicated by the problem that in a contenteditable element, things work differently, e.g. hitting Enter adds <p> markup.)

Custom CSS font won't work

For some reason the font I'm trying to add won't add itself to my website. I'd rather not do this with an image, so is it possible the font is broken? Would it be possible to fix it with just the otf or ttf?
My code (in case I'm missing something):
#font-face {
font-family: urbanJungle;
src: url('UrbanJungleDEMO.ttf');
}
h1 {
font-family: urbanJungle;
font-size: 100px;
color: #34495e;
}
Additional details: This is in the latest Chrome, other custom fonts work.
In the network console the font is red and it says cancelled.
Live URL: http://codestack.co.uk/website/
The font was from Dafont, no extra processing applied by myself, it's in the same directory as the index page. All the relevant CSS is included.
You should use Font Squirrel font-face generator for this: http://www.fontsquirrel.com/tools/webfont-generator
Different browsers need different font formats, you only provided one. The generator will convert your font to all the formats needed and give you a CSS file too, with no hassles.
You are using only TrueType font, IE support only *.eot fonts. And you are missing a lot informations. It is always better to use font stack instead of using single font, if first font went missing css use immediate next font on the list (called font-stack).
Here is an interesting article about #font-face by Paul Irish : Bulletproof #font-face Syntax
#font-face{
font-family:MyFont;
src:url(../font/MyFont.eot);
src:local('?'),
url(../font/MyFont.woff) format("woff"),
url(../font/MyFont.otf) format("opentype"),
url(../font/MyFont.ttf) format("Truetype"),
url(../font/MyFont.svg#myfont) format("svg");
font-weight: normal;
font-size:normal;
}
body{
font-family: "MyFont", Verdana, sans-serif; /* Font stack */
}

Why not define font-weight or font-style in #font-face, Font Squirrel?

When we define #font-face styles, we can define whether the referenced files are for the bold, italic, or bold italic versions of a font, as discussed in this SO question:
How to add multiple font files for the same font?
Example:
#font-face {
font-family: 'FontinSans';
src: local('☺'), url('fontin_sans_regular.woff') format('woff');
font-weight: normal;
font-style: normal;
}
#font-face {
font-family: 'FontinSans';
src: local('☺'), url('fontin_sans_bold.woff') format('woff');
font-weight: bold;
font-style: normal;
}
However, Font Squirrel doesn't generate #font-face kits this way. They do something like this instead:
#font-face {
font-family: 'FontinSans';
src: local('☺'), url('fontin_sans_regular.woff') format('woff');
font-weight: normal;
font-style: normal;
}
#font-face {
font-family: 'FontinSansBold';
src: local('☺'), url('fontin_sans_bold.woff') format('woff');
font-weight: normal;
font-style: normal;
}
Which means in our CSS files we have to do things like this:
h2 {
font-family: 'FontinSansBold', Verdana, sans-serif;
font-weight: normal;
}
Why doesn't Font Squirrel use the font-weight and font-style declarations to distinguish the bold and italic variants? Why use a separate font family? Do they know something about (lack of) support for this feature in some browser?
By default, Font-Squirrel does this in order to increase support with user-agents that do not follow specification (those that ignore font-weight and font-style).
If you do not care about those outdated user-agents, you may enable the "Style Linking" option which is available in the expert section of the #font-face kit generator. Note that IE8 and below ignores numbered font-weight values and only support normal and bold (and corresponding 400, 700 weight values).
It does involve poking around inside the font to determine when a font is bold or italic. And certain bits must be set inside the font in order for IE to pick up the style linking. Most bold / italic fonts have these bits set, but not all. We are working on a way to make this more automatic.
It seems Internet Explorer 8 may be one of those "older" user agents that doesn't support font-weight and font-style
I am trying to make bold/italic/bolditalic automatic using the #font-face and font-family.
My attempts so far have yielded nothing. Here is a page demonstrating the problem.
http://clearimageonline.com/apps/playground/fonts/test_IE.html
Anyone here encountered this and have a solution that works with IE8?
I have searched and fiddled most of this week for an answer to this. It appears that IE8 wont let me do this.
Here is a proposed workaround (very ugly workaround)....
http://clearimageonline.com/apps/playground/fonts/proposed_IE.html
These test pages are designed for Internet Explorer ONLY. This test is limited to IE. Cross Browser functionality will obviouosly be a part of a final solution.
The problem using the default FontSquirrel's approach is that if the fallback font loads, all weights will be lost because they are all set to normal. I think the style linking is the best approach.
If you are worried about IE8 users you can use a conditional css.

#font-face problem with font-weight in Safari

I just started using #font-face
This is on top of my css
#font-face {
font-family: Avenir;
src: url(../fonts/AvenirLTStd-Medium.otf);
}
body{
font-family:"Avenir",Helvetica;
background:#fff url(../images/main_bg.png) repeat-x scroll 0 0;
color:#321244;
}
and i have this below for a menu on joomla
#menu_bottom ul li a {
font-size:12px;
font-weight:600;
letter-spacing:-0.6px;
text-transform:uppercase;
this is on the html file
<li class="item23"><span>Menu Item</span></li>
This works in Firefox, but it is not working correctly on Safari or Chrome, the font is correct but the font-weight is not working, i checked on google-chrome developer tool and the computed font weight is 600.
I have tried using 100 or 900 the results on safari and chrome are the same, the font weight wont change.
Is there something wrong with my font-face declaration on top of my css file?
should i try adding something like this
#font-face {
font-family: Avenir;
src: url(../fonts/AvenirLTStd-Heavy.otf);
font-style: bold;
}
I tried but didnt work.
Should i add another font this are that i have on my font directory
AJensonPro-BoldIt.otf AvenirLTStd-BookOblique.otf
AJensonPro-Bold.otf AvenirLTStd-Book.otf
AJensonPro-It.otf AvenirLTStd-HeavyOblique.otf
AJensonPro-LtIt.otf AvenirLTStd-Heavy.otf
AJensonPro-Lt.otf AvenirLTStd-LightOblique.otf
AJensonPro-Regular.otf AvenirLTStd-Light.otf
AJensonPro-SemiboldIt.otf AvenirLTStd-MediumOblique.otf
AJensonPro-Semibold.otf AvenirLTStd-Medium.otf
AvenirLTStd-BlackOblique.otf AvenirLTStd-Oblique.otf
AvenirLTStd-Black.otf AvenirLTStd-Roman.otf
Or should i try another font format, something that is not otf, in IE seems to be working althought the width is bigger. I still need to fix that.
As explained here, you have to add
font-weight: normal;
font-style: normal;
inside the #font-face declaration and then use the font-weight:600; on your anchor.
Specifying a numerical value for font-weight is something you do at your peril. Different browsers interpret the values differently, and some don't interpret it as anything at all. You are best going with the standard "bold" ... which browsers get closest to matching in some semi-uniform way. Also, if you are using custom typefaces you should be certain your users have them on their systems. Also, some custom fonts don't respond well to the faux "bold" property. They will have a named "bold" face, like Avenir Bold, Avenir Black, Avenir Demibold, Avenir Demibold Condensed, etc., etc., etc.
Also, always include enough fallback fonts, including, at last, the "serif" or "sans-serif" or "monospace" general font specifier.
Better late than never. Hope this helps:
html { -webkit-font-smoothing: antialiased; }

Resources