Unicode CSS Font Awesome Icons Rendering as Boxes in React - css

I am using the jPlayer example in a create-react-app. Here is a CodeSandbox showing the issue of font-awesome icon's rendering as boxes.
The icons render via css rules specifying content as unicode for <i> tags with the fa class.
I installed the font-awesome dependency which was in the jPlayer example's package.json. Then, I implemented an AudioPlayer component and used the skins provided by jPlayer. The component renders but the icons are all boxes, and I can see the unicode content in the source.
Here's an example of the project architecture. This is the play button in /src/AudioPlayer/AudioPlayer.jsx.
<Play><i className="fa">{/* Icon set in css */}</i></Play>
Then, the AudioPlayer is imported into App.jsx. App.jsx imports a stylesheet which has this relevant rule:
.fa, .fas, .far {
font-family: FontAwesome !important;
}
App.jsx is then rendered by index.js. Inside index.js, we import the audio player's stylesheets:
// Styles the jPlayer to look nice
import 'react-jplayer/dist/css/skins/sleek.min.css';
// Styles Play/Pause/Mute etc when icons (<i />) are used for them
import 'react-jplayer/dist/css/controls/iconControls.min.css';
The rule for the play button in iconControls.css looks like this:
.jp-jplayer .jp-icon-controls .jp-play i:before {
content: "\F04B";
font-family: 'Font Awesome\ 5 Free';
font-weight: 900;
}
then within index.html's head I include the font-awesome CDN as a final attempt at fixing the boxes being rendered instead of font-awesome icons.

I think in the styles.css there is FontAwesome !important as shown below which is overriding the FontAwesome 5 Free font. You could remove this style to see the fonts coming up.
fa, .fas, .far {
font-family: FontAwesome !important;
}

Font characters show as open squares when:
The Unicode character specified doesn't exist in the font file.
The requested font file can't be found and there's no fallback specified.
Since its's Font Awesome, there's no fallback font AND the requested character doesn't exist in most fonts. So you get a double problem.
This almost always happens when the browser can't find the font file due to path issues. I'd look through your CSS to find where #font-face is requested and fix the path to match your project. I would guess this is in the player CSS file AND that it expect's a local file not from the CDN.
Also, be aware that Webpack sometimes moves files and updates paths found in CSS so you may need to move those to a "static" directory and change paths as needed.
Finally, you should check the name of the font to make sure it matches what you have available in your system. According to Font Awesome's Docs, it should be font-family: "Font Awesome 5 Free"; your's seems to have an extra back slash.

Related

Component CSS #Import conflict

In my login component's CSS, I am importing the following font:
#import url(https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght#1,600&display=swap);
In another component in the system, I would like to use this same font but I do not want it applied with italics. I am importing it in that component's CSS as:
#import url(https://fonts.googleapis.com/css?family=Open+Sans:300,400);
In this case, the component is rendering it as if the login page import was being used (the font appears in italics and at 600 font weight).
Until I refresh the page. If I do a refresh, it appears properly at 400 without the bold.
I have tried applying:
font-variation-settings: normal;
To the div containing the text, this has no effect.
What am I doing wrong?
Could be something related to the caching of css and fonts?
Maybe here you can find the answer.
LINKs:
Preloading fonts using angular CLI
Browser Caching of CSS files

unable to load #font_face in my wamp localhost?

I am trying to add some custom font in my site but unable to do. I am not sure if I am using a right or wrong path. Kindly help.
#font-face {
font-family: XfinityStandard
src: url('landingpage/fonts/XfinityStandard-Light.woff2') format("woff2");
where landingpage is folder name.
There are two main ways to check:
Is the font actually working (i.e. can you see it rendering properly), and
Inspect your page (e.g. in Chrome, right-click the text you expect the font to render on, and select Inspect from the drop-down menu. In your Styles tab, at the right-hand bottom of the page, there should be a section called Rendered Fonts. If you have implemented your font correctly, it should show here (in addition to the css hierarchy applied, where your font should be listed).
If your font is not showing here, make sure you follow the following:
The #font-face rule should be added to your css before any styles
Use your rule in your css by specifying the font as XfinityStandard and provide a fall-back like sans-serif, e.g. body { font-family: 'XfinityStandard', sans-serif; }
Make sure you have wide support, so when you specify your font, add an additional source for format('woff')
As Devansh J mentioned, make sure your font is relative to the css file
If you are still having issues, maybe consider a hosted font like Google Fonts, as follows: #import url(///fonts.googleapis.com/css?family=Montserrat which you can use as body { font-family: 'Montserrat', sans-serif; }

Font Awesome icons not showing using Ruby Gem

I'm using Font-awesome via the ruby gem (ruby-2.2.2, font-awesome-sass-4.3.2) and the font icons look fine locally, but are broken when viewed remotely or when deployed on a server.
I have followed the instructions laid out here but when I look at my compiled CSS the expected unicode numbers have been replaced by boxes:
.fa-glass:before {
content: "";
}
instead of
.fa-glass:before {
content: "\f000";
}
I have already tried including #charset "UTF-8"; at the top of my SASS file which imports font-awesome.
Ideas anyone?
Edit: 17/06/15
I've raised this issue with Font-awesome themselves. Hopefully they'll shed some light on it.
The problem isn't that the escaped chars are replaced with unescaped chars in the CSS.
The problem is that the font file hasn't loaded and that is why you see black boxes instead of the correct glyphs.
When looking at the CSS sent to the browser from your example site that you linked from Font-Awesomes github I can see invalid urls for the font.
font-family: 'FontAwesome';
src: url(font-path("font-awesome/fontawesome-webfont.eot"));
This means that the scss hasn't been properly parsed in your application.

If I'm using the bootstrap.min.css file from MaxCDN instead of a downloaded bootstrap file, how do I load new custom icons I have in my font set?

I was previously using a downloaded bootstrap.min.css file version, and I had added
.glyphicon-location2:before{content:"\e948"}
in-line to that file (which was a custom edit included in a website template). I had updated my glyphicon font set using icomoon, and am referencing that downloaded font set in my project file. Now, I want to use the CDN version of bootstrap.min.css to speed up loading of my page, but that appears to only reference the default glyphicons, because my custom glyphicons are missing from the webpage output.
How much speed increase "should" the preloaded CDN version result in?
Where do I put the glyphicon reference that pulls icons from my custom local file glyph set? Do I have to override the default font source and point to the local font set, similar to the answer in this thread (keeping in mind I'm not using SCSS or Node)?
how does $icon-font-path works in bootstrap scss?
Can I override the default glyphicons by adding
#font-face {
font-family:'Glyphicons Halflings';
src:url('fonts/glyphicons-halflings-regular.eot');
src:url('fonts/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'),
url('fonts/glyphicons-halflings-regular.woff') format('woff'),
url('fonts/glyphicons-halflings-regular.ttf') format('truetype'),
url('fonts/glyphicons-halflings-regular.svg#glyphicons-halflingsregular') format('svg')
}
to my style.css file, or do I have to override the bootstrap.min.css font handling elsewhere?
Here's a snippet of CSS code that I was able to make the glyph icons appear. Try using the font-family as shown below. FYI this enhances Bootstrap's accordion
.panel-heading .accordion-toggle:after {
/* symbol for "opening" panels */
font-family: 'Glyphicons Halflings'; /* essential for enabling glyphicon */
content: "\e114"; /* adjust as needed, taken from bootstrap.css */
float: right; /* adjust as needed */
color: #328ED1; /* adjust as needed */
}
.panel-heading .accordion-toggle.collapsed:after {
/* symbol for "collapsed" panels */
content: "\e080"; /* adjust as needed, taken from bootstrap.css */
}
So I did some experimentation and "discovered" that yes, declaring the new glyphicons as a #font-face in my custom styles.css file (which is linked below my CDN bootstrap import in my html in order to override the defaults) works just like having the font declared in my original downloaded bootstrap.min.css file. Ahem... no points for originality.

Using a different font with twitter bootstrap

I want to use a different font for my website, which is not a regular webfont. I have created EOT files already. Now how can I integrate those fonts with twitter bootstrap ? Can anyone help ?
Thanks
The easiest way I've seen is to use Google Fonts.
Go to Google Fonts and choose a font, then Google will give you a link to put in your HTML.
Then add this to your custom.css:
h1, h2, h3, h4, h5, h6 {
font-family: 'Your Font' !important;
}
p, div {
font-family: 'Your Font' !important;
}
or
body {
font-family: 'Your Font' !important;
}
You can find a customizer on the official website, which allows you to set some LESS variables, as #font-family-base. Link your custom fonts in your layout, and use your custom generated bootstrap style.
Link here
For an example with the #font-face rule, using WOFF format (which is pretty good for browser compatibility), add this CSS in your app.css file and include your custom boostrap.css file.
#font-face {
font-family: 'Proxima Nova';
font-style: normal;
font-weight: 400;
src: url(link-to-proxima-nova-font.woff) format('woff');
}
Please note Proxima Nova is under a license.
Hi you can create a customized build on bootstrap, just change the font name in the following pages
Bootstrap 2.3.2
http://getbootstrap.com/2.3.2/customize.html#variables
Bootstrap 3
http://getbootstrap.com/customize/#less-variables
After that, make sure to use proper #font-face in a css file and link that to your page. Or you could use font kit generators.
you can customize twitter bootstrap css file, open the bootstrap.css file on a text editor, and change the font-family with your font name and SAVE it.
OR got to http://getbootstrap.com/customize/ and make a customized twitter bootstrap
First of all you have to include your font in your website (or your CSS, to be more specific) using an appropriate #font-face rule.
From here on there are multiple ways to proceed. One thing I would not do is to edit the bootstrap.css directly - since once you get a newer version your changes will be lost. You do however have the possibility to customize your bootstrap files (there's a customize page on their website). Just enter the name of your font with all the fallback names into the corresponding typography textbox. Of course you will have to do this whenever you get a new or updated version of your bootstrap files.
Another chance you have is to overwrite the bootstrap rules within a different stylesheet. If you do this you just have to use selectors that are as specific as (or more specific than) the bootstrap selectors.
Side note: If you care about browser support a single EOT version of your font might not be sufficient. See http://caniuse.com/eot for a support table.

Resources