Font-Awesome css not working locally - html

I would like to use Font Awesome locally without using the cdn.
My code fails to add font awesome icons to my page.
I can make it work easily using the cdn link but the local link fails to do anything.
Thanks
Jason.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>How it Works | Rubberdesk </title>
<!-- Bootstrap Core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Font-Awesome CSS -->
<link href="/font-awesome-4.3.0/css/font-awesome.min.css" rel="stylesheet">

Writing this may be helpful for someone like me :
Actual folder of font-awesome.min.css is public/css/font-awesome.min.css
In font-awesome.min.css file font-family source refers to URL *'../fonts/fontawesome-webfont.eot'. So following files must be located in public/fonts/
FontAwesome.otf
fontawesome-webfont.eot
fontawesome-webfont.svg
fontawesome-webfont.ttf
fontawesome-webfont.woff
fontawesome-webfont.woff2

What you have to do when you use bootstrap/font-awesome files locally is:
Path stored must be clear.
Path written inside the font-awesome.min.css should equal to (1)
Version must have the same.
the fonts in folder fonts/ are indeed related to font-awesome.min.css you've got right now.
you must know how to write it on your script, as in; <span class="fa fa-home"></span>, etc.

use all.css ,not fontawesome-min.css.
ref to : https://fontawesome.com/how-to-use/on-the-web/setup/hosting-font-awesome-yourself

Check the path is right and placed in right folder
try this code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>How it Works | Rubberdesk </title>
<!-- Bootstrap Core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Font-Awesome CSS -->
<link href="font-awesome-4.3.0/css/font-awesome.min.css" rel="stylesheet">
check path
check path in bootstrap.min.css
are all same
It will look same as in question try this

You need to link to the all.css file or the all.min.css file for font-awesome to work locally on your pc and make sure you copy the webfonts folder to the font-awesome folder.

Here is an update for version 5.8.1. As mentioned above you need to download the font files locally in order to run font Awesome locally.
The folder to use is now called /webfonts
Download these files locally and put them in a folder called /webfonts.
Example: (https://use.fontawesome.com/releases/v5.8.1/webfonts/fa-brands-400.eot)
The css is referencing the following URL's.
../webfonts/fa-brands-400.eot
../webfonts/fa-brands-400.woff2
../webfonts/fa-brands-400.woff
../webfonts/fa-brands-400.ttf
../webfonts/fa-brands-400.svg
../webfonts/fa-regular-400.eot
../webfonts/fa-regular-400.woff2
../webfonts/fa-regular-400.woff
../webfonts/fa-regular-400.ttf
../webfonts/fa-regular-400.svg
../webfonts/fa-solid-900.eot
../webfonts/fa-solid-900.woff2
../webfonts/fa-solid-900.woff
../webfonts/fa-solid-900.ttf
../webfonts/fa-solid-900.svg
Total size is around 2.5 MB for all the font files.

I tried to implement serving font-awesome.min.css in my Django project.
Issue 1.
My first problem was how to serve the font files themselves. Initially the browser would come up with error (of font files not being accessible).
However the browser errors themselves were quite revealing:
Hovering the mouse pointer on the error lines would throw the following:
"..../static/my_project/fonts/fontawesome-webfont.woff2?v=4.7.0"
So this solved my first problem as to where the font files should reside. It's telling me to put them in the sub-folder "fonts" in the static folder created (defined in the "settings.py" file like this):
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
And the following in "urlpatterns" (in the project's urls.py file):
static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
So the path of the .css file and the associated fonts would be something like this:
project_root
------ static
-------app_name
--------css
----------font-awesome.min.css
--------fonts
----------<font_files>
Next was the problem of font files themselves.
Issue 2: Where are the font files?
Initially I downloaded the font file by following the CDN path in by the browser (i.e. the css file itself along with the associated files which also included the folder named "webfonts"). But even after the folder was copied to the "fonts" folder the fonts were not served up and browser continued to generate errors.
In the ".css" file the font files are referred to but the referenced files/paths themselves were not available in the "webfonts" folder (as also confirmed by the browser error as stated above ("..../static/my_project/fonts/fontawesome-webfont.woff2?v=4.7.0").
On searching the web for "fontawesome-webfont.woff2" I came across the site which had the files listed for download:
fontawesome-webfont.eot
fontawesome-webfont.ttf
fontawesome-webfont.woff
fontawesome-webfont.woff2
FontAwesome.otf
Once the files (s.no. 1 - 5 above) were copied in the folder "fonts" the fonts were served up successfully and as desired.

Thanks for all of your help everyone.
It looks like it was an "fa fa-icon" class issue. I thought I had them in there but they must have been lost during editing - probably due to poor version control.
I think I've been using some 3.x.x code by mistake.
Interesting that everything still worked using the cdn code.
Thanks again. Should be able to fix everything now.
Jason.

I had the same issue on Mac OS. My solution was to
sudo chown -R _www:staff project/

Related

Why am I getting an Error 404 when I try to GET my css file?

I am trying to import a css file in the same directory as my HTML file:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home Page</title>
<link rel="stylesheet" href="./styles.css">
</head>
I believe I am correct in using ./ to go through my directory. I have also tried using ../
However, in my dev tools in chrome, I am getting this error:
Failed to load resource: the server responded with a status of 404 (NOT FOUND)
Any help would be appreciated. Thanks!
It is definitely the link that's the error.
You will need to check your file path, is this project just simply on your desktop? Is it a ASP.NET app?
Depending on where/what project it is, you should be safe to use .. to traverse up one folder
It really depends how your directory folder is structured, but if you have your HTML and CSS files in the same folder, you can just use <link rel="stylesheet" href="/styles.css"> (note that there's no dot), then your html file will look in the root folder of your project, also make sure the name styles.css is the same as your css file
Since you put the html file and the css file in the same folder, there is no need to use ./ or ../ because this step is written only if the css file is in another folder next to the html file
open-source public files work best. So instead, go to https://gist.github.com and sign up if you haven't already, name the file (with extension, e.g. style.css), and paste your CSS3 code, click 'create secret gist', and click raw. copy the link and that will be your external CSS file.
-Good luck!

Have an icon next to page title using html / ejs

I am trying to put an icon next to my page title. I have read quite a few articles and similar questions on the internet but i still can't see my little icon up there next to the page title. I literally don't know what is wrong with my code.
I have the following directories among other: data/public, data/files, public (which includes all my css files), views (which includes all my ejs files). Inside the /views folder i have a few folders and a few files that are responsible for my viewing experience while using the web app i am building. Now in the /views/includes directory i have a file named head.ejs which contains all my head code i will use in pretty much every other ejs file. so i just have the head.ejs file and i can include it in every ejs file i want. The head.ejs file looks like that:
<!DOCTYPE html>
<html lang="en">
<head>
<!-- <link rel="shortcut icon" href="/data/public/boxTitle.jpg" type="image/jpg" /> -->
<link rel="icon" href="favicon.ico" type="image/x-icon" />
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title><%= pageTitle %></title>
<link rel="stylesheet" href="/css/main.css">
I expected to see the icon up there but still haven't seen it. I have tried to move my favicon.ico image around in different directories and play a bit around with the paths. the best for me is for the image to be in the /data/public/ directory. while the head.ejs is in the /views/includes/ directory. The image is 16x16, black and white. Tried with a jpg image, too. I am probably failing really hard cause it's seems pretty easy and straight forward but... Any help is appreciated! I will delete the post if the answer is totally obvious and the post is worthless.
Assuming your icon is in your public folder inside an images folder.
If you have defined your public folder as you mentioned, with something like this:
app.use(express.static(path.join(__dirname, 'public')));
then you can easily display your icon this way:
<link rel="icon" href="/images/your-icon" type="image/x-icon" />

why i have to rename the css file so that it can be work, is there something wrong?

I have finished editing the css file and saving it
but my css file doesn't work and doesn't change the display at all
and css files are also not loaded
but after I renamed the css file, everything work properly
css file loaded and the display changes
is there something wrong with the structure of my folder?
or is there something wrong with my coding?
my custom css is
<link rel="stylesheet" href="../style/index.css">
and this is my head tag
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="../css/bootstrap.min.css">
<!-- Custom CSS -->
<link rel="stylesheet" href="../style/index.css">
<link rel="stylesheet" href="../css/pace.css">
<!-- Font Awesome -->
<link rel="stylesheet" href="../css/fontawesome.css">
<title>Dashboard • Sistem Pakar</title>
</head>
my folder structure
act/
|---.....
|
assets/
|---.....
|
css/
|---.....
|
js/
|---.....
|
lib/
|---.....
|
style/
|---index.css
|
app/
|---index.php
If you are facing the issue that you are changing the css code but changes are not reflecting on browser. Its because browser cache your css and do not reload it from server (files). To manually reload it you need to:
Reload page by pressing ctrl+F5
Use some extension to clear cache of your browser
rename css file name so that browser can load new file
use some task runner like grunt etc to uglify and rename your css
you can try any of above method for you convenience
One trick that is useful to know about is the "disable cache" browser function.
As it sound, it disable caching while DevTools is open.
More information here : https://stackoverflow.com/a/7000899/4614064
Also, if you use Webpack or Gulp, you can use hashing to output a different filename so the browser has to reload it properly. In development, "disable cache" within the browser should be enough.
The web browser's or web server's cache is the reason for what is happening,
You can use a string after your css file like this and after every change, you can change the version and it will work.
<link rel="stylesheet" href="../style/index.css?ver=1.0.0">
Please note that the query string (the portion of the uri after ?) can be anything, as long as it is a valid query string and different each time you make a change.

How to set favicon.ico properly on vue.js webpack project?

I have created a vue webpack project using vue-cli.
vue init webpack myproject
And then ran the project under dev mode:
npm run dev
I got this error:
Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:8080/favicon.ico
So inside webpack, how to import the favicon.ico correctly?
Check out the Project Structure of webpack template: https://vuejs-templates.github.io/webpack/structure.html
Note that there is a static folder, along with node_modules, src, etc.
If you put some image into the static folder, like favicon.png, it will be made available at http://localhost:8080/static/favicon.png
Here is the documentation for static assets: https://vuejs-templates.github.io/webpack/static.html
For your favicon issue, you can put a favicon.ico or favicon.png into the static folder and refer in the <head> of your index.html as follows:
<head>
<meta charset="utf-8">
<link rel="shortcut icon" type="image/png" href="/static/favicon.png"/>
<title>My Vue.js app</title>
...
</head>
If you do not define a favicon.ico in your index.html, then the browser will request for a favicon from the website root (default behaviour). If you specify a favicon as above, you will not see that 404 anymore. The favicon will also start showing up in your browser tabs.
As a side note, here is the reason why I prefer PNG instead of ICO file:
favicon.png vs favicon.ico - why should I use PNG instead of ICO?
For some reason, the above solutions did not work for me before converting the default favicon.ico file to favicon.png and renaming it to favicon-xyz.png e.g. (I have put this file in /public folder) and edited the index.html file as follows:
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="icon" href="<%= BASE_URL %>favicon-xyz.png">
.
.
.
</head>
Might be useful for someone.
Little update for Laravel 5/6/7/8/9, place your favicon.ico or favicon.png into the /public folder and refer to it in your index.html like this:
<head>
<meta charset="utf-8">
<link rel="shortcut icon" type="image/png" href="/favicon.png"/>
<title>My Vue.js app</title>
...
</head>
Hope it helps !
As of 2022, #Mani answer is a little outdated as static assets are now served in public folder other than static.
Just generate a .ico favicon file (this site provides free online favicon generation), rename it to favicon.ico and place it in public folder, no need to change index.html, reload and new favicon will be displayed.
You may use vue-pwa-asset-generator in order to generate a full set of favicons foreach platform.
Thanks. This did the trick as per eightballs comments. I needed to move the file to the /public folder and rename it :D
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>gear.png">
<title>Prodigy</title>
</head>
Just add shortcut in rel tag like that :
<link rel="shortcut icon" href="<%= BASE_URL %>favicon.ico">

File won't show in folder, but will show in root directory?

I got an empty website up and running online. Basic html5 page with a style link and a script link. It looks like this:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Taco Bell at midnight</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="css/styles.css" />
<script src="js/scripts.js" type="text/javascript"></script>
</head>
<body>
</body>
</html>
The src's are accurate, I have a folder in the same directory as the html page with the name css and js. When I try to visit them, it shows them as blank. However, when I drag the files out to the same directory as the parent, and update the href, it shows them with the content. Does anyone have an idea as to why this is happening?
It seems relevant to add I just purchased the domain today from GoDaddy, and am using x10hosting for free hosting.
UPDATE: The styles.css still appears in my home directory (in chrome, not cpanel) after being moved, and ctrl+f5'ing, and it now also appears in the folder css/styles.css as well???
UPDATE2: Now it appears as though the files are just updating really slowly? I see the changes in codeanywhere/cpanel immediately, but chrome takes like half an hour to get the changes, regardless of clearing my history/cache and ctrl+f5'ing.
x10hosting (free version, I haven't tested paid version) cache is really bad, this seems to be a server issue, sometimes it keeps showing files that you deleted hours ago, sometimes it won't show files that didn't exist beforem, you might need to wait for hours.