Sass font-face syntax not loading font-family - css

Can anyone tell me why this is not loading at all? When I inspect the element, the inspector is showing "Times Roman" Used as "Times"
This is from my main.scss file:
body,
html {
height: 100%;
font-size: 100%;
#font-face {
font-family: 'proxima_nova_reg';
src: url('../media/fonts/proxima_nova_reg.eot'); /* IE9 Compat Modes */
src: url('../media/fonts/proxima_nova_reg.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('../media/fonts/proxima_nova_reg.woff') format('woff'), /* Modern Browsers */
url('../media/fonts/proxima_nova_reg.ttf') format('truetype'), /* Safari, Android, iOS */
url('../media/fonts/proxima_nova_reg.svg#svgFontName') format('svg'); /* Legacy iOS */
}
section{
font-family: 'proxima_nova_reg' !important;
}
}
It is then converted to the following via phpstorm's sass watch:
body,
html {
height: 100%;
font-size: 100%; }
#font-face {
body,
html {
font-family: 'proxima_nova_reg';
src: url("../media/fonts/proxima_nova_reg.eot");
/* IE9 Compat Modes */
src: url("../media/fonts/proxima_nova_reg.eot?#iefix") format("embedded-opentype"), url("../media/fonts/proxima_nova_reg.woff") format("woff"), url("../media/fonts/proxima_nova_reg.ttf") format("truetype"), url("../media/fonts/proxima_nova_reg.svg#svgFontName") format("svg");
/* Legacy iOS */ } }
body section,
html section {
font-family: 'proxima_nova_reg' !important; }
No errors or warnings, but I also do not see any fonts being downloaded under the network tab.
Do I need to set the chmod of fonts to something special? They are currently 755
first edit - I changed the files to chmod 777 proxima_nova_reg.* while they look they have changed, but under the fonts tab, it still reads as Times
As usual, thanks in advance

Thanks to comments from #Ry- it put me on the right track. I changed my scss file to the following, which places the font-face rules before the html, body:
#font-face {
font-family: 'proxima_nova_reg';
src: url('../media/fonts/proxima_nova_reg.eot'); /* IE9 Compat Modes */
src: url('../media/fonts/proxima_nova_reg.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('../media/fonts/proxima_nova_reg.woff') format('woff'), /* Modern Browsers */
url('../media/fonts/proxima_nova_reg.ttf') format('truetype'), /* Safari, Android, iOS */
url('../media/fonts/proxima_nova_reg.svg#svgFontName') format('svg'); /* Legacy iOS */
}
body,
html {
height: 100%;
font-size: 100%;
section{
span{
font-family: 'proxima_nova_reg';
}
}
}
As a result, phpstorm's watch sass creates the following css file, which renders the fonts correctly:
#font-face {
#font-face {
font-family: 'proxima_nova_reg';
src: url("../media/fonts/proxima_nova_reg.eot");
/* IE9 Compat Modes */
src: url("../media/fonts/proxima_nova_reg.eot?#iefix") format("embedded-opentype"), url("../media/fonts/proxima_nova_reg.woff") format("woff"), url("../media/fonts/proxima_nova_reg.ttf") format("truetype"), url("../media/fonts/proxima_nova_reg.svg#svgFontName") format("svg");
/* Legacy iOS */ }
body,
html {
height: 100%;
font-size: 100%; }
body section span,
html section span {
font-family: 'proxima_nova_reg'; }
/*# sourceMappingURL=main.css.map */
Thank you all for your help

Related

Font is thinned out at the edges when using #font-face

When I am adding a font to my website via a google fonts tag, my font displays fine. But when I add it as a file via #font-face, it gets thinned out.
Example:
Here's the code that I use:
.title {
color: white;
font-family: 'myBodoni', serif;
position: absolute;
top: 120px;
left: 200px;
font-size: 64px;
z-index: 2;
line-height: normal;
}
.img {
position: relative;
margin: 3%;
}
#font-face {
font-family: myBodoni;
src: url(bodoni-variable.ttf); //variable file downloaded directly from google fonts
}
When I add this code, it works properly:
Css:
font-family: 'Bodoni Moda', serif;
Html
<link href="https://fonts.googleapis.com/css2?family=Bodoni+Moda&display=swap" rel="stylesheet">
Here's how it looks with the following code
It is because you are only adding one #font-type. You need to add #font-type for eot, woff2, woff & svg:
#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 */
}

Custom icon set not displaying in Safari

I created some icons using FontForge, and the icons work in all modern browsers except for Safari. What would be causing Safari to be the only browser that doesn't display the fonts?
This is the SCSS that is being used:
#font-face {
font-family: 'MyFont';
src: url('/assets/fonts/MyFont.woff2') format('woff2');
font-weight: normal;
font-style: normal;
}
.my-font-icon {
font-family: 'MyFont';
display: inline-block;
speak: none;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
text-rendering: auto;
line-height: 1;
-webkit-font-smoothing: antialiased;
&:before {
font-family: 'MyFont';
display: inline-block;
speak: none;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
text-rendering: auto;
line-height: 1;
-webkit-font-smoothing: antialiased;
}
&.my-font-questions:before {
content: "\0001";
}
&.my-font-chevron-left:before {
content: "\0002";
}
&.my-font-close:before {
content: "\0003";
}
}
Safari requires the TrueType/ttf font version and really you should be including several different types rather than just woff2 which is the most modern type. Here's a sample list from the CSS Tricks article here, the browser finds the font it understands and renders that one:
#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 */
}
FontForge should provide you these other font types, but if it doesn't, you'll need to go to FontSquirrel to render them (if you have the licence and permission to do so):
https://www.fontsquirrel.com/tools/webfont-generator

Icons used via fonts (hosted locally) won't display in Firefox

I'm locally hosting my icons in the form of fonts, using #font-face in font.css.sass file, and referencing that in a generic style.css.scss file. (I've essentially copy-pasted-modified from a site for generating social media icons, PerfectIcons.com. The icons appear exactly as expected in all browsers except Firefox. Even so, Firefox receives and renders my other #font-face fonts with no issue.
Perhaps the problem is related to the svg file that is used for the social icons, and the way Firefox handles that?
NB. the asset_url below is something for Rails 4 and Heroku.
#font-face {
font-family: 'si';
src: asset_url('socicon.eot');
src: asset_url('socicon.eot?#iefix') format(embedded-opentype),
asset_url('socicon.woff') format(woff),
asset_url('socicon.ttf') format(truetype),
asset_url('socicon.svg') format(svg);
font-weight:400;
font-style:normal;
}
#media screen and (-webkit-min-device-pixel-ratio:0) {
#font-face {
font-family: 'si';
src: asset_url('socicon.svg') format(svg);
}
}
And then the style.css.scss:
.soc
overflow: hidden
margin: 0
padding: 0
list-style: none
text-align: right
margin-right: 100px
.soc li
display: inline-block
*display: inline
zoom: 1
.soc li a
font-family: si !important
font-style: normal
font-weight: 400
-webkit-font-smoothing: antialiased
-moz-osx-font-smoothing: grayscale
-webkit-box-sizing: border-box
-moz-box-sizing: border-box
-ms-box-sizing: border-box
-o-box-sizing: border-box
box-sizing: border-box
text-decoration: none
text-align: center
display: block
position: relative
z-index: 1
width: 35px
height: 35px
line-height: 35px
font-size: 19px
#include border-radius(50px)
color: #c9c8c8
background-color: #383838
opacity: .8
.soc-icon-last
margin: 0 !important
.soc-twitter:before
content: 'a'
.soc-facebook:before
content: 'b'
.soc-google:before
content: 'c'
The format specifiers need to be in quotes as shown below:
#font-face {
font-family: 'si';
src: asset_url('socicon.eot');
src: asset_url('socicon.eot?#iefix') format('embedded-opentype'),
asset_url('socicon.woff') format('woff'),
asset_url('socicon.ttf') format('truetype'),
asset_url('socicon.svg') format('svg');
font-weight:400;
font-style:normal;
}
Just replace this code with your code:
#font-face {
font-family: 'si';
src: url('<%= asset_path('socicon.eot') %>');
src: url('<%= asset_path('socicon.eot) + '?#iefix' %>') format('embedded-opentype'),
url('<%= asset_path('socicon.woff') %>') format('woff'),
url('<%= asset_path('socicon.ttf') %>') format('truetype'),
url('<%= asset_path('socicon.svg') %>') format('svg');
font-weight:400;
font-style:normal;
}
Change css file extention to .css.scss.erb

#font-face works in Chrome and Safari, but not in Firefox

Chrome and Safari are showing the (local) be fonts correctly, but Firefox isn't.
The code I got from Fontsquirl added ' marks in the code, which I got rid of, but it's still not working:
Original code:
#font-face {
font-family: 'frutigerboldcn';
src: url('frutiger_67_bold_condensed-webfont.eot');
src: url('frutiger_67_bold_condensed-webfont.eot?#iefix') format('embedded-opentype'),
url('frutiger_67_bold_condensed-webfont.woff') format('woff'),
url('frutiger_67_bold_condensed-webfont.ttf') format('truetype'),
url('frutiger_67_bold_condensed-webfont.svg#frutigerboldcn') format('svg');
font-weight: normal;
font-style: normal;
I changed it into:
#font-face {
font-family: frutigerboldcn;
src: url(frutiger_67_bold_condensed-webfont.eot);
src: url(frutiger_67_bold_condensed-webfont.eot?#iefix) format(embedded-opentype),
url(frutiger_67_bold_condensed-webfont.woff) format(woff),
url(frutiger_67_bold_condensed-webfont.ttf) format(truetype),
url(frutiger_67_bold_condensed-webfont.svg#frutigerboldcn) format(svg);
font-weight: normal;
font-style: normal;
Fonts are loaded in the same folder as the stylesheet.
This is part of the stylesheet regarding the navigation:
#navigation .sf-menu a {
display: inline;
display: inline-block;
font-size: 16px;
text-transform: uppercase;
color: #008abf;
border-radius: 2px;
padding: 0 5px;
height: 26px;
line-height: 26px;
font-weight: normal;
letter-spacing: 1px;
font-family: frutigerboldcn;
How do I fix this? Thanx in advance
Put the following in your .htaccess and all will be fine, at least on modern FF versions.
<FilesMatch "\.(ttf|otf|eot)$">
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>
</FilesMatch>
Go here for the full discussion on Stack Overflow:
CSS #font-face not working with Firefox, but working with Chrome and IE
#font-face {
font-family: 'ArialRounded';
src: url('ArialRounded.eot');
src: local('ArialRounded'), url('fonts/ArialRounded.eot'); /* for firefox */
}
#font-face {
font-family: 'ArialRounded';
src: url('ArialRounded.woff') format('woff'),
src: local('ArialRounded'), url('fonts/ArialRounded.woff'); /* for firefox */
url('ArialRounded.svg#ArialRounded') format('svg');
src: local('ArialRounded'), url('fonts/ArialRounded.svg'); /* for firefox */
}

#font-face is not working on Chrome, Firefox, IE

This is my CSS code:
The font is not working. Did I miss something?
I want to mention that it's not installed on the local OS and I'm sure that the URL goes to the font exactly
#font-face {
font-family: 'ma';
src: url('http://localhost/header/images/FS_Old.ttf');
}
.menu_head {
width: 100%;
position: relative;
height: 30px;
font-family: 'ma';
}
Ryan is right. I replaced your URL with a working URL and it works absolutely fine.
This is what I used.
#font-face {
font-family: 'ma';
src: url('http://www.cse.buffalo.edu/~rsd7/BaroqueScript.ttf');
}
.menu_head {
width: 100%;
position: relative;
height: 30px;
font-family: 'ma';
}
It should probably because Chrome, Firefox ,IE does not support ttf extension. You can try to put other extension:
#font-face {
font-family: 'ma';
src: url('FS_Old.eot'); /* IE9 Compat Modes */
src: url('FS_Old.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('FS_Old.ttf.woff') format('woff'), /* Modern Browsers */
url('FS_Old.ttf.ttf') format('truetype'), /* Safari, Android, iOS */
}
I used this website to convert the font to other types http://www.fontsquirrel.com/tools/webfont-generator and used a different supported font type and that seems to have solved the problem. Here is new code that works with all browsers.
<html>
<head>
<style>
#font-face {
font-family: 'baroque_scriptregular';
src: url('baroquescript.eot');
src: url('baroquescript.eot?#iefix') format('embedded-opentype'),
url('baroquescript.woff') format('woff'),
url('baroquescript.ttf') format('truetype'),
url('baroquescript.svg#baroque_scriptregular') format('svg');
font-weight: normal;
font-style: normal;
}
.menu_head {
width: 100%;
position: relative;
height: 30px;
font-family: baroque_scriptregular;
}
</style>
</head>
<body>
<div class="menu_head" >
hellod
</div>
</body>

Resources