rails and bootstrap with custom fonts? - css

I am trying to learn how to use custom fonts however I keep getting a jquery error I think it is? while trying to load the fonts.
It's this error here:
jquery.self-c64a74367bda6ef8b860f19e74df08927ca99d2be2ac934e9e92d5fd361e0da4.js?body=1:3735 GET http://localhost:3000/assets/fonts/dayslater/dayslater.ttf
I have added this line inside application.rb:
config.assets.paths << Rails.root.join("app", "assets", "fonts")
my css:
#font-face {
font-family: 'dayslater';
src: url('fonts/dayslater/dayslater.ttf') format('truetype');
}
please note that these bits of CSS are in different files but even in the same file they do not work.
#dayslat {
font: 3em 'dayslater';
font-weight: bold;
color: white;
text-align:center;
}
I was just wondering why it will not work thank you

I managed to get this working, thanks to Igor.
He pointed out that instead of having
font: 3em 'dayslater';
It should instead be:
font-family: 'dayslater';
font-size: 3em;
and also adding this line in application.rb:
config.assets.precompile << /\.(?:svg|eot|woff|ttf)\z/
however what the problem was, rails now automatically detects font files,
so when I had
fonts/--font folder--/font.ttf
It should have been:
--font folder--/font.ttf

Try this:
#dayslat {
font-family: 'dayslater';
font-size: 3em;
font-weight: bold;
color: white;
text-align:center;
}
add in application.rb below string:
config.assets.precompile << /\.(?:svg|eot|woff|ttf)\z/
in your css use:
#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 */
font-style: normal;
font-weight: normal;
}
with your own font-name

Related

Load font locally via CSS

I have a small static website and I need to move it on an USB to make it possible to open it via this USB.
Via CSS I defined those rules for the fonts (Is a custom font):
#font-face {
font-family: 'MyFont_SerifReg';
src: url('/assets/fonts/MyFontSerifReg.ttf') format('truetype');
src: url('/assets/fonts/MyFontSerifReg.eot'); /* IE9 Compat Modes */
src: url('/assets/fonts/MyFontSerifReg.eot?#iefix') format('embedded-opentype'); /* IE6-IE8 */
src: url('/assets/fonts/MyFontSerifReg.woff') format('woff'); /* Pretty Modern Browsers */
}
#font-face {
font-family: 'MyFont_SansBol';
src: url('/assets/fonts/MyFontSansBol.ttf') format('truetype');
src: url('/assets/fonts/MyFontSansBol.eot'); /* IE9 Compat Modes */
src: url('/assets/fonts/MyFontSansBol.eot?#iefix') format('embedded-opentype'); /* IE6-IE8 */
src: url('/assets/fonts/MyFontSansBol.woff') format('woff'); /* Pretty Modern Browsers */
}
#font-face {
font-family: 'MyFont_SansLig';
src: url('/assets/fonts/MyFontSansLig.ttf') format('truetype');
src: url('/assets/fonts/MyFontSansLig.eot'); /* IE9 Compat Modes */
src: url('/assets/fonts/MyFontSansLig.eot?#iefix') format('embedded-opentype'); /* IE6-IE8 */
src: url('/assets/fonts/MyFontSansLig.woff') format('woff'); /* Pretty Modern Browsers */
}
#font-face {
font-family: 'MyFont_SansDem';
src: url('/assets/fonts/MyFontSansDem.ttf') format('truetype');
src: url('/assets/fonts/MyFontSansDem.eot'); /* IE9 Compat Modes */
src: url('/assets/fonts/MyFontSansDem.eot?#iefix') format('embedded-opentype'); /* IE6-IE8 */
src: url('/assets/fonts/MyFontSansDem.woff') format('woff'); /* Pretty Modern Browsers */
}
body {
font-family: 'MyFont_SansLig';
}
h2 {
font-family: 'MyFont_SerifReg';
font-size: 40px !important;
}
h4 {
font-family: 'MyFont_SansBol';
line-height:1.5em;
}
p {
font-family: 'MyFont_SansLig';
font-size:16px;
}
b {
font-family: 'MyFont_SerifReg';
font-size:18px;
}
And I have no problem to load the fonts while visiting the website via We
EDIT:
A screen from the Console, Looks like the "fonts" folder is not loaded in "Sources"
Console
The problem appears only when I try to load the website in Local: the font's are not loaded.
What am I writing wrong?
It might be because the path problem.
Try to use relative path (assume the assets folder is at the same place as the html): ../assets/fonts/MyFontSerifReg.ttf
#font-face {
font-family: 'MyFont_SerifReg';
src: url('/assets/fonts/MyFontSerifReg.ttf') format('truetype'),
url('/assets/fonts/MyFontSerifReg.woff') format('woff');
}
Please make sure to cross-check below trouble shooting guide:
path provided in url()
Apply Style as below for example:
body{
font-family: 'MyFont_SerifReg'; // Same name defined in rule
}
Add reference of your CSS file where rules are defined in HTML.

Define one font face for several font files with different weight

I came across this issue using custom fonts. Many offer several files to support different font weights and italics, so you will define a font face like:
#font-face {
font-family: 'WebFont Bold';
src: url('myfont.woff') format('woff'), /* Chrome 6+, Firefox 3.6+, IE 9+, Safari 5.1+ */
url('myfont.ttf') format('truetype'); /* Chrome 4+, Firefox 3.5, Opera 10+, Safari 3—5 */
}
Where Bold will be replaced with different font specific words like italic or light. I was wondering is it possible to define one font face that will use specific font, say bold if somewhere in css font-weight: bold; is set?
The correct way to do it is like this:
#font-face {
font-family: 'WebFont';
src: url('myfont_regular.woff')....
}
#font-face {
font-family: 'WebFont';
font-weight: bold;
src: url('myfont_bold.woff')....
}
You can set the same name for different font like:
#font-face {
font-family: 'MyFont';
src: url('myfont.woff') format('woff'),
url('myfont.ttf') format('truetype');
font-weight: normal;
}
#font-face {
font-family: 'MyFont';
src: url('myfont-bold.woff') format('woff'),
url('myfont-bold.ttf') format('truetype');
font-weight: bold;
}
And using like:
p {
font-family: 'MyFont';
}
strong {
font-family: 'MyFont';
font-weight: bold;
}

Custom font no being applyed on CSS

Could someone tell me what's wrong here..? I've checked it many times and can not find the problem. Page always loads with Impact instead of Corbert font.
Also, when I check what is happening trough Firebug, 'corbert' name displays grey, and when hovering it, the miniature that Firebug shows as a font demo, is not Corvert, like if it did not find the files:
CSS code (I have also tried setting the first one to .eot)
#font-face {
font-family: ‘corbert’;
src: url('corbert-regular.ttf');
src: url('corbert-regular.eot?#iefix') format('embedded-opentype'),
url('corbert-regular.woff') format('woff'),
url('corbert-regular.ttf') format('truetype'),
url('corbert-regular.svg#adlerRegular') format('svg');
font-weight: normal;
font-style: normal;
}
*, *:before, *:after {
-moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;
}
body {
overflow-x: hidden; height:100%; width:100%; margin:0; padding:0; font-family:'corbert',Fallback, impact;
}
Here you have a screen of the folder with linked fonts:
You have typographic apostrophes around the font name, so the name is actually ‘corbert’ rather than corbert.
Use regular apostrophes:
font-family: 'corbert';
Also, is the SVG name of the font really adlerRegular, and not something like corbertRegular?
my fool proof #font-face code (taken from someone else's excruciating troubleshooting, but I can't remember who...):
#font-face {
font-family: 'fontname';
src: url('fonts/fontname.eot'); /* IE9 Compat Modes */
src: url('fonts/fontname.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('fonts/fontname.woff') format('woff'), /* Modern Browsers */
url('fonts/fontname.ttf') format('truetype'), /* Safari, Android, iOS */
url('fonts/fontname.svg#svgFontName') format('svg'); /* Legacy iOS */
}
note that there are two src and there are # on a couple of lines.
and the order seems to matter quite a bit
[edit: it's from here]
I always refer to this blog post when I'm having trouble with custom fonts; Bulletproof #font-face Syntax.
In short, you should be using:
#font-face {
font-family: 'corbert';
src: url('corbert-regular.eot?') format('eot'),
url('corbert-regular.woff') format('woff'),
url('corbert-regular.ttf') format('truetype');
}

Why Firefox ignores custom font from #font-face?

Let’s say we have a font-face section like that
#font-face {
font-family: 'F';
src: url("/fonts/F.eot?") format("embedded-opentype");
src: local('?'),
url("/fonts/F.woff") format("woff"),
url("/fonts/F.ttf") format("truetype"),
url("/fonts/F.svg") format("svg");
font-weight: normal;
font-style: normal;
}
and a body style
body {
font-family: 'F' /*, sans-serif*/;
}
Now, if I uncomment sans-serif it will take priority over custom font despite the fact it is mentioned at the end. Why? How do I specify a back-up variant for those who can’t use downloadable webfonts?
===upd===
If in doubt why local('?') is used, look here http://paulirish.com/2009/bulletproof-font-face-implementation-syntax/#smiley
I was wrong in my thinking that it is sans-serif breaking my CSS, here is actual code that shows custom 'F' font. If 'Trebuchet MS' will be uncommented, font-family drops to sans.
body {
font-family: 'F' /*, 'Trebuchet MS'*/ , sans-serif;
}
Your syntax seems to be slightly incorrect. The '?' at the end of the first 'src' property value is aimed towards fixing IE versions 6 through 8, but could actually be affecting Firefox. The correct syntax to use is:
#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 */
}
Source: http://www.fontspring.com/blog/further-hardening-of-the-bulletproof-syntax

#font-face doesn't work

I downloaded a font inlove-light-wf.ttf, in order to use the rule #font-face.
I have in my folder: home.html and inlove-light-wf.ttf.
In my CSS I have :
#font-face {
font-family: 'Inlove';
src: url('inlove-light-wf.ttf');
font-weight: normal;
font-style: normal;
}
#definicao{
text-align:center;
color:#0080C0;
font-family:'Inlove';
font-size:24px;
margin-top:20px;
border-top:solid #999 thin;
padding: 20px 40px 3px 40px;
height:290px;
background-color:#EFEFEF;
}
#definicao{
text-align:center;
color:#0080C0;
font-family:'Inlove';
font-size:24px;
margin-top:20px;
border-top:solid #999 thin;
padding: 20px 40px 3px 40px;
height:290px;
background-color:#EFEFEF;
}
But it doesn't work.
One source of the problem could be if your css is in a separate file that isn't in the root folder. For example, if you keep all of your css files in a 'css' folder, you'll need to modify the font url to be relative to that file, not to the root folder. In this example it would be src: url('../inlove-light-wf.ttf');
Furthermore, not all browsers can use .ttf font files. You have to declare alternative font formats in the #font-face css.
Here's a modified #font-face declaration to get you started. I would also recommend reading more here and here.
#font-face {
font-family: 'Inlove';
src: url('inlove-light-wf.eot'); /* IE9 Compat Modes */
src: url('inlove-light-wf.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('inlove-light-wf.woff') format('woff'), /* Modern Browsers */
url('inlove-light-wf.ttf') format('truetype'), /* Safari, Android, iOS */
url('inlove-light-wf.svg#svgFontName') format('svg'); /* Legacy iOS */
}
The #font-face rule usually doesn't support some old browsers. I usually use font-face generator which will generate css file from your font that you need to include, and all browsers will show it correctly.
I had problems with font too. When font was working in IE wasn't on iPhone and when was working on iPhone wasn't in IE. Here is my code (i don't know why it works this way, but it does for me):
#font-face{
font-family:"Royal Chicken";
src: url(../gradivo/font/RoyaChicken.eot);
src: url(../gradivo/font/RoyalChicken.ttf) format("truetype"), /* Safari, Android, iOS */
url(../gradivo/font/RoyalChicken.eot?#iefix) format("embedded-opentype"), /* IE6-IE8 */
url(../gradivo/font/RoyalChicken.woff) format("woff"), /* Pretty Modern Browsers */
url(../gradivo/font/RoyalChicken.svg#RoyalChicken) format("svg");
}
#font-face{
font-family:"Royal Chicken";
src: url(../gradivo/font/RoyaChicken.eot);
}
#font-face{
font-family:"Royal Chicken";
src: url(../gradivo/font/RoyalChicken.ttf) format("truetype");
}
It may help you. :)

Resources