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
Related
I am currently using <span class="icon-home2"></span> to show icons in my CSS file:
#font-face {
font-family: 'icomoon';
src: url('fonts/icomoon.eot?4r9x8o');
src: url('fonts/icomoon.eot?4r9x8o#iefix') format('embedded-opentype'),
url('fonts/icomoon.ttf?4r9x8o') format('truetype'),
url('fonts/icomoon.woff?4r9x8o') format('woff'),
url('fonts/icomoon.svg?4r9x8o#icomoon') format('svg');
font-weight: normal;
font-style: normal;
}
[class^="icon-"], [class*=" icon-"] {
/* use !important to prevent issues with browser extensions that change fonts */
font-family: 'icomoon' !important;
speak: none;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
line-height: 1;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.icon-home:before {
content: "\e900";
}
Now I have a different requirement in which I need show the icons, with content in CSS, using unicode that is mapped here:
.icon-home:before {
content: "\e900";
}
Can anyone tell me how can I achieve this?
I got the answer:
add in css file
[data-icon]:before {
font-family: icomoon; /* BYO icon font, mapped smartly */
content: attr(data-icon);
speak: none; /* Not to be trusted, but hey. */
}
and access with
<i aria-hidden="true" data-icon=""></i>
remember to append &#x before unicode of icons eg icon code is e001 then data-icon=""
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 */
}
On my website I'm using a custom font which I have uploaded. It seems to be choosing when to work intermittently. It works on some computers/browsers, but not on others. It is also mapped correctly.
This is my code:
<style type="text/css">
#font-face {
font-family: 'AgencyFBRegular';
src: url('agencyr.eot');
src: url('agencyr.eot?#iefix') format('embedded-opentype'),
url('agencyr.woff') format('woff'),
url('AGENCYR.TTF') format('truetype'),
url('agencyr.svg#AgencyFBRegular') format('svg');
}
h3 { font-family: 'Agency FB', sans-serif; font-size: 26px; font-weight:normal; text-align: left; line-height: 100%;
border-bottom: 1px solid #484848; padding-bottom: 5px; margin-bottom:7px;
</style>
I thought it was working everywhere until I used a friend's laptop to view it.
Can you see where I'm going wrong?
UPDATE:
I have updated font CSS. It seems to be working, but now not on iOS.
The following code should work:
#font-face {
font-family:"AgencyFBRegular";
src: url("agencyr.eot") /* EOT file for IE */
}
#font-face {
font-family:"AgencyFBRegular";
src: url("agencyr.ttf") /* TTF file for CSS3 browsers */
}
h3 {
font-family:'Agency FB', sans-serif;
font-size: 26px;
font-weight:normal;
text-align: left;
line-height: 100%;
border-bottom: 1px solid #484848;
padding-bottom: 5px;
margin-bottom:7px;
}
You need change file name of your font without Uppercase. Like this: from AGENCYR.TTF to agencyr.ttf
and in your css file:
src: url('agencyr.ttf');
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>
Edit:
Chrome is somehow rendering the fonts i use via #font-face incorrectly. Which i found as i changed the font family of the inspected element to arial. The reason this might be, is because as i was searching for a fix on how chrome renders fonts so they appear more smooth instead of pixelated, i found that you could swap the order of the font formats and put the svg on top which would cause chrome to render it perfectly. As seen here.
So either the order is messing them up, or simply the font is broken in some way.
Now the question is, how do i use this font without breaking the site and keeping the fonts smooth?
Here is the #font-face code i use:
#font-face {
font-family: 'alegreya_scregular';
src: url('../includes/fonts/alegreyasc-regular-webfont.eot');
src: url('../includes/fonts/alegreyasc-regular-webfont.eot?#iefix') format('embedded-opentype'),
url('../includes/fonts/alegreyasc-regular-webfont.svg#alegreya_scregular') format('svg'),
url('../includes/fonts/alegreyasc-regular-webfont.woff') format('woff'),
url('../includes/fonts/alegreyasc-regular-webfont.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
#font-face {
font-family: 'droid_sansregular';
src: url('../includes/fonts/droidsans-webfont.eot');
src: url('../includes/fonts/droidsans-webfont.eot?#iefix') format('embedded-opentype'),
url('../includes/fonts/droidsans-webfont.svg#droid_sansregular') format('svg'),
url('../includes/fonts/droidsans-webfont.woff') format('woff'),
url('../includes/fonts/droidsans-webfont.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
#font-face {
font-family: 'droid_sansbold';
src: url('../includes/fonts/droidsans-bold-webfont.eot');
src: url('../includes/fonts/droidsans-bold-webfont.eot?#iefix') format('embedded-opentype'),
url('../includes/fonts/droidsans-bold-webfont.svg#droid_sansbold') format('svg'),
url('../includes/fonts/droidsans-bold-webfont.woff') format('woff'),
url('../includes/fonts/droidsans-bold-webfont.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
I have some rendering issues on chrome. For some reason, the links right side gets cut off so the underlines will only fill half the of text, and the divs on the right side will not break off the words to a new line. It only happens some of the time and if i refresh the page a couple of times (differs how many times) it will fix itself eventually. Images are below.
Note: The site is in danish.
Images, underlined the issues in red:
http://i.stack.imgur.com/zJHXD.jpg
What causes this, and how do i fix it?
Note: This is for the navigation links
HTML:
<ul class="nav">
<li class="first"></li>
<li>Forside</li>
<li>Booking</li>
<li>Galleri</li>
<li>Begivenheder</li>
<li>Events</li>
<li>Politik</li>
<li>Kontakt</li>
</ul>
CSS:
.header .nav {
position: absolute;
overflow: hidden;
font-size: .70em;
bottom: -8px;
right: 16px;
}
.header .nav li {
float: left;
background: #171717 url(../images/site/nav_divider.png) repeat-y right;
text-transform: uppercase;
} .header .nav li:hover {
background: #1a1a1a url(../images/site/nav_divider.png) repeat-y right;
}
.header .nav .first {
width:2px;
height:31px;
margin-bottom:-0.95em;
}
.header .nav li a {
display: block;
padding: .75em .85em .75em .75em;
color: #e0e0e0;
text-decoration: none;
}
After a bit of searching on #font-face and chrome behaviour, i found a solution to the problem. Apparently moving the svg to the top will make the rendered font break the layout, so instead you should keep the original formatting and add a special media query, which will render the font smoothly in chrome while not breaking the layout.
Example:
#font-face {
font-family: 'droid_sansregular';
src: url('../includes/fonts/droidsans-webfont.eot');
src: url('../includes/fonts/droidsans-webfont.eot?#iefix') format('embedded-opentype'),
url('../includes/fonts/droidsans-webfont.woff') format('woff'),
url('../includes/fonts/droidsans-webfont.ttf') format('truetype'),
url('../includes/fonts/droidsans-webfont.svg#droid_sansregular') format('svg');
font-weight: normal;
font-style: normal;
}
#media screen and (-webkit-min-device-pixel-ratio:0) {
#font-face {
font-family: 'droid_sansregular';
src: url('../includes/fonts/droidsans-webfont.svg#droid_sansregular') format('svg');
font-weight: normal;
font-style: normal;
}
}