Webfont not working on mobile, even with multiple formats - webfonts

I purchased a webfont from MyFonts (Kokomo Breeze Regular) and it's working fine on desktop, but won't show up on mobile.
I've added all different file formats using #font-face, but it's still not working on mobile:
#font-face {
font-family: "Kokomo Breeze";
src: url({{ 'kokomo-breeze.eot' | asset_url }});
src: url({{ 'kokomo-breeze.eot?#iefix' | asset_url }}) format('embedded-opentype'),
url({{ 'kokomo-breeze.woff2' | asset_url }}) format('woff2'),
url({{ 'kokomo-breeze.woff' | asset_url }}) format('woff'),
url({{ 'kokomo-breeze.ttf' | asset_url }}) format('truetype'),
url({{ 'kokomo-breeze.svg#kokomo-breeze' | asset_url }}) format('svg');
}
I've also tried adding this to the top of my stylesheet, as it says to do in the MyFonts instructions:
/**
* #license
* MyFonts Webfont Build ID 3780250, 2019-07-01T14:26:51-0400
*
* The fonts listed in this notice are subject to the End User License
* Agreement(s) entered into by the website owner. All other parties are
* explicitly restricted from using the Licensed Webfonts(s).
*
* You may obtain a valid license at the URLs below.
*
* Webfont: KokomoBreeze-Regular by Nicky Laatz
* URL: https://www.myfonts.com/fonts/nicky-laatz/kokomo-breeze/regular/
* Copyright: Nicky Laatz
* Licensed pageviews: 100,000
*
*
* License: https://www.myfonts.com/viewlicense?type=web&buildid=3780250
*
* © 2019 MyFonts Inc
*/
/* #import must be at top of file, otherwise CSS will not work */
#import url("//hello.myfonts.net/count/39ae9a");
This is the website I am working on: https://www.persuasion-nation.com/
Thanks!

Hullo, Mary. Welcome to Stack Overflow.
I believe the issue may be with your link to the font file. I have never seen the syntax that you are using before: src: url({{ 'kokomo-breeze.eot' | asset_url }});
A clear link to the font file is required, for example: src: url('webfonts/32457D_0_0.eot');
This link to the font file must be relative to the css script that is calling it. If you are using internal css (as it appears that you may be), then you should make the font url relative to the html script which calls it:
So your link would be something like /Fonts/thefontname.woff2
For a full and working example, I have pasted a currently-working script below.
Note also: definitely do as you say you are with the adding of the licence script.
/**
* #license
* MyFonts Webfont Build ID 3237525, 2017-02-14T14:25:07-0400
*
* The fonts listed in this notice are subject to the End User License
* Agreement(s) entered into by the website owner. All other parties are
* explicitly restricted from using the Licensed Webfonts(s).
*
* You may obtain a valid license at the URLs below.
*
* Webfont: RockwellStd-BoldCondensed by Monotype
* URL: http://www.myfonts.com/fonts/mti/rockwell/std-bold-condensed/
* Copyright: Copyright 1990, 2002 Adobe Systems Incorporated. All Rights Reserved. Copyright 1990, 2002 The Monotype Corporation. All rights reserved.
* Licensed pageviews: 250,000
*
*
* License: http://www.myfonts.com/viewlicense?type=web&buildid=3237525
*
* © 2017 MyFonts Inc
*/
/* #import must be at top of file, otherwise CSS will not work */
#import url("//hello.myfonts.net/count/32457d");
#font-face {font-family: 'RockwellStd-BoldCondensed';
src: url('webfonts/32457D_0_0.eot');
src: url('webfonts/32457D_0_0.eot?#iefix') format('embedded-opentype'),
url('webfonts/32457D_0_0.woff2') format('woff2'),
url('webfonts/32457D_0_0.woff') format('woff'),
url('webfonts/32457D_0_0.ttf') format('truetype');}
This should be repeated for each font file, i.e. kokomo-breeze-regular, kokomo-breeze-bold, kokomo-breeze-condensed, etc, etc
Hoping this helps you out. Ask any needed questions in comments.
-Parapluie

Related

"#font-face declaration doesn't follow the fontspring bulletproof syntax" error when trying to implement custom font

I'm trying to add a custom font to my website, but keep getting the same error no matter what I try, and I can't find much about how to go about fixing it.
Here's my code:
#font-face {
font-family: "Moderna";
src: url("/MODERNA.TTF")
}
Suggestions?
The fontspring bulletproof syntax is just a recommendation. It declares your #font-face must satisfy below syntax to work properly in most cases:
#font-face {
font-family: 'MyFontFamily';
src: url('myfont-webfont.eot?') format('eot'),
url('myfont-webfont.woff') format('woff'),
url('myfont-webfont.ttf') format('truetype'),
url('myfont-webfont.svg#svgFontName') format('svg')
}
Most browsers supports TTF fonts now but if you can't see the font in browser try this
#font-face {
font-family: "Moderna";
src: url("/MODERNA.TTF") format("ttf");
}
And if my memory serves me then the rule must be on top of your css file. And please check the file /MODERNA.TTF exists.
Pretty sure your path/url is causing this issue:
src: url("/MODERNA.TTF")
implies you're entering a direcory named 'MODERNA.TTF' and not a file.
As #Mik pointed out the recommended declaration should be fine – unless your file couldn't be found.
Depending on your html/css file structure it should rather be something like this:
(granted your font file resides in the same directory as your css.
#font-face {
font-family: 'Moderna';
src: url('MODERNA.eot?') format('eot'),
url('MODERNA.woff') format('woff2'),
url('MODERNA.woff') format('woff'),
url('MODERNA.ttf') format('truetype'),
url('MODERNA.svg#svgFontName') format('svg')
}
Keep also in mind, that referencing font files via #font-face is case-sensitive (there might be exceptions).
So double check if your exact font file name is really using uppercase letters (MODERNA.TTF or moderna.ttf).

How are different styles and weights of web fonts rendered?

This is a general question about why certain font weights and styles need to be specifically included, but not others.
I use Open Sans and Roboto Mono web fonts on my website, hosted on Google fonts, with the basic <link href="https://fonts.googleapis.com/css?family=Open+Sans|Roboto+Mono" rel="stylesheet"> statement in the HTML head. As one would expect, I don't have to specify that I want bold font weight or italic style text in the <link>; all browsers can generally handle <foo style="font-weight: bold"> and <foo style="font-style: italic"> and render those stylistic changes, even though it's technically a separate font (of the same typeface) that I haven't included.
However, if I wanted <foo style="font-weight: lighter"> (or <foo style="font-weight: 200">) and <foo style="font-style: oblique">, it won't render: lighter just looks like normal, and oblique looks like italic.
I know how to make it work, obviously; I'm just wondering two things:
How does the browser "make" the bold and italic (and bold-italic) versions of a typeface without the font?
Why can't it "make" the lighter and oblique versions?
NB: Typeface refers to the set of typographical symbols and characters in a particular shape (eg: Open Sans or Roboto Mono), and font is the typeface in a specific style (eg: Open Sans 400 italic or Roboto Mono 200 Italic)
You can find user friendly explanations to your question on the font-weight MDN page, including:
Meaning of relative weights
Base element Bolder Lighter
-----------------------------------------
100 400 100
200 400 100
300 400 100
400 700 100
500 700 100
600 900 400
700 900 400
800 900 700
900 900 700
Common font weight mapping.
A more technical set of documentation can be found in official specs.
The current Candidate Recommendation CSS Fonts Module is Fonts Module Level 3 which is unchanged from the counterpart definition in Fonts Module Level 1.
In CSS Font Module Level 4 (currently working draft) there are a few notable changes proposed:
font-weight numeric values will vary from 1 to 1000
there might be additional strings mapped to particular numeric values (i.e: thin => 100, medium => 500, etc).
Browsers currently display the closest available font weight to 400 for font-weight: normal and the closest available font weight to 700 for font-weight: bold.
To make sure a particular font-weight is used, you need to:
load the weight
specify the exact numeric weight for your element(s).
To load multiple font weights from font files, use multiple #font-face declarations:
#font-face {
font-family: 'MyWebFont';
src: url('myfont-normal.woff2') format('woff2'),
url('myfont-normal.woff') format('woff'),
url('myfont-normal.ttf') format('truetype');
}
#font-face {
font-family: 'MyWebFont';
src: url('myfont-bold.woff2') format('woff2'),
url('myfont-bold.woff') format('woff'),
url('myfont-bold.ttf') format('truetype');
font-weight: bold;
}
#font-face {
font-family: 'MyWebFont';
src: url('myfont-italic.woff2') format('woff2'),
url('myfont-italic.woff') format('woff'),
url('myfont-italic.ttf') format('truetype');
font-style: italic;
}
#font-face {
font-family: 'MyWebFont';
src: url('myfont-bold-italic.woff2') format('woff2'),
url('myfont-bold-italic.woff') format('woff'),
url('myfont-bold-italic.ttf') format('truetype');
font-weight: bold;
font-style: italic;
}
In the above example, the file names don't really matter. What matters is that they point to the file containing the correct font style and font weight glyphs.
For Google fonts, it's easier. When loading more than just the default weight, specify all weights and styles as comma separate values, after the font-family name followed by a colon:
<link href="https://fonts.googleapis.com/css?family=MyFamily:n,i,b,bi" rel="stylesheet">
Besides n (normal), bi (bolditalic), you can also load numeric values: 400, 400i.
To find out more on how to load multiple weights, styles and subsets of the same font family from Google, you should read their "Getting started" page.
Note the required font styles, weights and subsets need to be available in order to be usable. If you request something that does not exist, Google will return the closest match to your request from available weights/styles/subsets.
You can easily see a list of available weights, styles and subsets on each font page and the correct URL will be generated for you by checking the appropriate checkboxes.

Rails 5 + Rails Assets + Fontawesome does not load fonts

On installing Fontawesome via rails-asset.org, and following the default instructions, the fonts don't load correctly and all I see is boxes, indicating, the url's being generated to load the font are incorrect.
UPDATE : Save yourselves some time and switch gems. Here are the steps. I found that even with my previous answer there are path issues in production. However its easiest to get fontawesome working with:
gem 'font-awesome-rails'
#import "font-awesome"; in your scss file
Done!
Ignore everything below this! unless you absolutely want to use gem 'rails-assets-fontawesome'
So looks like this is a bug in the library and the asset pipeline does not find the path. The fix suggested in the issue does not work any more because the path seems to have changed since and there is no hyphen in font-awesome path anymore.
Here's the correct fix:
Create a new file app/assets/stylesheets/font-awesome.scss with content:
fa-font-path: "fontawesome/fonts";
#import "fontawesome";
In application.scss include:
*= font-awesome
This should fix the problem and icons should start showing up.
Remarks:
If you choose to move the font-awesome.scss inside some directory under app/assets/stylesheets/somedir/font-awesome.scss, then you need to fix the fa-font-path variable to have correct relative path like so:
fa-font-path: "../fontawesome/fonts";
Be careful with paths and names!
The file you create cannot be called fontawesome.scss as this is the name used by the packaged gem.
If you have newest version of the gem rails-assets-fontawesome (4.7.0) then the import and fa-font-path will use fontawesome and not font-awesome as in older versions of this gem. Not sure how far back in versions this behavior goes.
I have it worked with adding these lines to config/initializers/assets.rb:
Rails.application.config.assets.paths << Rails.root.join('node_modules')
# font-awesome fonts
Rails.application.config.assets.precompile << %r{font-awesome/fonts/[\w-]+\.(?:eot|svg|ttf|woff2?)$}
and having this as mentioned in other answers:
application.scss
$fa-font-path: "fontawesome/fonts";
#import "fontawesome";
Run rake assets:precompile and you should see font files in public/assets/font-awesome/fonts
For 5.5.0 version it should be look like this:
$fa-font-path: 'fontawesome/web-fonts-with-css/webfonts';
#import "fontawesome";
// Copy-paste of these files:
// #import "fontawesome/solid";
// #import "fontawesome/regular";
// But url() replaced with font-url()
#font-face {
font-family: 'Font Awesome 5 Free';
font-style: normal;
font-weight: 400;
src: font-url('#{$fa-font-path}/fa-regular-400.eot');
src: font-url('#{$fa-font-path}/fa-regular-400.eot?#iefix') format('embedded-opentype'),
font-url('#{$fa-font-path}/fa-regular-400.woff2') format('woff2'),
font-url('#{$fa-font-path}/fa-regular-400.woff') format('woff'),
font-url('#{$fa-font-path}/fa-regular-400.ttf') format('truetype'),
font-url('#{$fa-font-path}/fa-regular-400.svg#fontawesome') format('svg');
}
.far {
font-family: 'Font Awesome 5 Free';
font-weight: 400;
}
#font-face {
font-family: 'Font Awesome 5 Free';
font-style: normal;
font-weight: 900;
src: font-url('#{$fa-font-path}/fa-solid-900.eot');
src: font-url('#{$fa-font-path}/fa-solid-900.eot?#iefix') format('embedded-opentype'),
font-url('#{$fa-font-path}/fa-solid-900.woff2') format('woff2'),
font-url('#{$fa-font-path}/fa-solid-900.woff') format('woff'),
font-url('#{$fa-font-path}/fa-solid-900.ttf') format('truetype'),
font-url('#{$fa-font-path}/fa-solid-900.svg#fontawesome') format('svg');
}
.fa,
.fas {
font-family: 'Font Awesome 5 Free';
font-weight: 900;
}
Can't comment above, but shouldn't it be:
$fa-font-path: "fontawesome/fonts";
You can right above the suggested import by the gem:
#import "fontawesome";
if fontawsome 4.*...
Copy fonts from fontawsome/fonts for rails public folder: public/fonts
After about a day and a half of learning ALL about the asset pipeline, its cache and other fun topics, here's how I finally got this to work...
Rails 5.2.1
Font Awesome 6 Pro (loaded via npm using .npmrc with license key)
Using SCSS
Also using font-awesome-rails (but only for the helpers - notice there is no #import "font-awesome"; below)
# config/initializers/assets.rb
# Adde node_modules/ to the asset pipeline
Rails.application.config.assets.paths << Rails.root.join('vendor', 'assets', 'node_modules')
# Pre-compile any font files located in the asset pipeline
# This tells Rails to precompile the font files, fingerprint them, and place them in /public/assets/ (in the same subdir where they live in the pipeline)
# e.g.
# node_modules/#fortawesome/fontawesome-pro/webfonts/fa-solid-900.ttf (pipeline path)
# public/assets/#fortawesome/fontawesome-pro/webfonts/fa-solid-900-229b67ef16372975f562838a5c9f9bd2d9d9905ccc9c77f34c45f3d1f18f016f.ttf (pre-compiled asset path)
Rails.application.config.assets.precompile << /\.(?:svg|eot|woff|woff2|ttf)$/
# application.scss
#import "#fortawesome/fontawesome-pro/scss/fontawesome.scss";
// Don't use provided font imports b/c we need to use font-url to get asset paths with fingerprints!
// $fa-font-path: "../webfonts"; // Don't use this
// #import "#fortawesome/fontawesome-pro/scss/regular.scss"; // Don't use this
#import "fonts"; // Use this instead so that we can use font-url
# fonts.scss
/* Font Awesome 6 */
#font-face {
font-family: 'Font Awesome 6 Pro';
font-style: normal;
font-weight: 900;
src: font-url("#fortawesome/fontawesome-pro/webfonts/fa-solid-900.woff2") format("woff2"),
font-url("#fortawesome/fontawesome-pro/webfonts/fa-solid-900.ttf") format("truetype"); }
#font-face {
font-family: 'Font Awesome 6 Pro';
font-style: normal;
font-weight: 400;
src: font-url("#fortawesome/fontawesome-pro/webfonts/fa-regular-400.woff2") format("woff2"),
font-url("#fortawesome/fontawesome-pro/webfonts/fa-regular-400.ttf") format("truetype"); }
#font-face {
font-family: 'Font Awesome 6 Brands';
font-style: normal;
font-weight: normal;
src: font-url("#fortawesome/fontawesome-pro/webfonts/fa-brands-400.woff2") format("woff2"),
font-url("#fortawesome/fontawesome-pro/webfonts/fa-brands-400.ttf") format("truetype"); }
Also, one of the hardest things about this was realizing that my production environment wasn't working the same as my dev environment so I only realized the issue after deploying :( Here's how to avoid that...
# config/environments/development.rb
# Don't use pipeline if asset path fails
# config.assets.compile defaults to true in dev...so if the pre-compiled asset doesn't exist in public/assets/..., it will just pull from the pipeline and you won't know that you have an issue until you deploy!
config.assets.compile = false # This will raise an exception if the pre-compiled asset not found!
config.assets.debug = false # Pre-compile assets into single file
config.assets.digest = true # Use fingerprinting
Now, of course, this means you need to pre-compile your assets in development, so you need to run bundle exec rake assets:precompile from the root directory of your project. This will pre-compile your assets and place them in /public/assets/
If you run into a cache issue where the pre-compiler doesn't actually re-compile a resource, you can delete the Sprockets cache by running rm -r tmp/cache/assets
Once you have successfully migrated your asset changes to production, I would recommend reverting development.rb back to the defaults for efficient development. Also, you may want to bundle exec rake assets:clobber to delete the pre-compiled assets.
Here's some other good info I found after the fact...
https://guides.rubyonrails.org/asset_pipeline.html#in-development
Hope this helps someone save several hours of "rabbit-holing" :)

▾ and ✓ characters not showing up in IE8

Im using ▾ and ✓ characters which are inputted by the user so I chant use their full html value (something like this ✓).
These are working fine in Chrome, FF and IE9. However in IE8 they are replaced by a square character (see image below).
When I want unicode characters on IE8, I use
<span class="unicode">unicode characters here</span>
and
.unicode {
font-family: 'DejaVu Serif';
}
#font-face {
font-family: 'DejaVu Serif';
src: url('fonts/DejaVuSerif.eot');
src:local('DejaVu Serif'),
local('DejaVu Serif Book'),
url('fonts/DejaVuSerif.eot?#iefix') format('embedded-opentype'),
url('fonts/DejaVuSerif.woff') format('woff'),
url('fonts/DejaVuSerif.ttf') format('truetype'),
url('fonts/DejaVuSerif.svg#font') format('svg');
}
Where DejaVu fonts are public domain fonts that provide a wider range of characters. You can download their .ttf fonts here, and convert them to the other types using online tools.
You can use the Wingdings font, but Mozilla and Opera are standard-compiliant. Wingdings is not standard (what a surprise coming from Microsoft) because not mapped to Unicode, and so should never be used on a website.
However, do not despair, most symbols are available in Unicode : check
http://www.alanwood.net/demos/wingdings.html
The symbol you want is number 252 in the list.

font-face not working externally

I am trying to use a custom font which works locally for me, but i need to link it too an external website due to a specific requirement.
But as soon as i test it on my localhost when it is linked to my domain - the fonts dont show up
Im not sure if their is a cross domain issue - but any help would be appreciated cheers
#font-face {
font-family: "Wisdom";
src: url("http://transformer.tamar.com/Santa/726318360-Wisdom-Script.eot?#iefix") format("embedded-opentype"),
url("http://transformer.tamar.com/Santa/726318360-Wisdom-Script.svg#Wisdom Script AI") format("svg"),
url("http://transformer.tamar.com/Santa/726318360-Wisdom-Script.woff") format("woff"),
url("http://transformer.tamar.com/Santa/726318360-Wisdom-Script.ttf") format("truetype");
}
h3.step {
font-family: 'Wisdom';
font-size: 1em;
text-align: center;
}
#font-face URL's must be relative.
Example:
src: url("/Santa/726318360-Wisdom-Script.ttf") format("truetype");
Extra explanations about Relative URLs
Font-embedding, that is, the #font-face requires the font file to be created on a per-domain basis.
That's because the some fonts might have copyright issues