Have an icon next to page title using html / ejs - html

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" />

Related

My Favicon won't Appear

Ok so recently I started building a website and I realized that I needed a favicon so I made one put it in a favicon generator got it out and I have tried linking to it, and just plain inserting the image in the head but I can't seem to get it to work. It is a 16x16 photo saved as favicon.ico It still won't show up? it's in the same folder as my html along with the rest of the website do I need to put "http://favicon.com" instead I have tried using the debugger and network inspector but it won't acknowledge that's it there could it be the photo itself because I made it in illustrator then made it a jpg in photoshop?
Here's my code:
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="keywords" content="resume, mason britt, portfolio">
<link rel="shortcut icon" href="favicon.ico">
</head>

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">

Favicon.ico doesn't appear in title bar

I am trying to add a favicon.ico in my title but it is not working. The image and the HTML file are in the same folder but it still can't show me the favicon icon.
<title><link href="\Users\fjoni_000\Desktop\Stuff\Projects\Programming\favicon.ico" rel="shortcut icon">Best Of Internet | Front page</title>
This is the code that I am using. I tried with the Google logo and still it didn't show. This is the code from Google source code:
<link href="/images/branding/product/ico/googleg_lodp.ico" rel="shortcut icon">
If there is any question similar to mine and has the answer that I'm looking for then please comment it. Also the website is locally hosted NOT online
The <link> should not be within the <title>... it should be outside of the <title> but still within the <head>...
<head>
<title>Best Of Internet | Front page</title>
<link href="\Users\fjoni_000\Desktop\Stuff\Projects\Programming\favicon.ico" rel="shortcut icon">
...
Although I think the main issue you have is it looks like a local system path, not a URL as understood by your browser. And you're also missing the type attribute
Without knowing the setup of your website server... I would take a complete guess that you want something like...
<link href="/Programming/favicon.ico" rel="shortcut icon" type="image/x-icon" />
Just as an additional point, if you're able to... simply placing the favicon.ico file in the root of your domain is enough for the majority of browsers to pick up. Then you don't need the <link> at all
You could try to clear your browser cache and try again.
Do you have a live URL?
you adding Favicon inside the title tag which is wrong and make sure the icon exist in path. try this
<title>your title</title>
<link href="/images/branding/product/ico/googleg_lodp.ico" rel="shortcut icon">

Font-Awesome css not working locally

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/

Adding a theme to MVC page, can't find css file

Its been a little while by now, that I have been trying to understand MVC. I do understand the basics now and I also noticed, themes or css files can be added to a MVC site. When I try to do this, it seems my CSS file is not being found. This is the head of my _Layout.cshtml code:
<head>
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>#ViewBag.Title - Bierownie</title>
<link href="#Url.Content("~/Content/Earthlingtwo/style.css")"
rel="stylesheet" type="text/css" />
</head>
I am not really sure what I should put at the link tag. I noticed that in the other (standard auto-generated(Razor)) _Layout.cshtml file, something like this was being used:
#Styles.Render("~/Content/css")
#Scripts.Render("~/bundles/modernizr")
But it seemed that the code wouldn't understand if I put that same bit of code in the Layout's head, from which I want to use. I also tried to search on the web and I think it had something to do with the config file, although I'm not sure. A red curve would appear beneath Styles and Scripts.
If anyone could tell me how I simply could link a css file in a newly created layout file, I would be able to go further with my MVC site.
I am also not so sure if this question has already been asked and/or solved, so please let me know, as I couldn't find any answers.
As you can see in this picture:
There's a config file which will break the theme. Someone else noticed it and it did cause a problem.
You can just Drag&Drop css file from solution explorer to your layout page.
Bundle uses better. Try this:
ASP.NET - Using Bundle and Minification in ASP.NET MVC 4 and ASP.NET Web Forms 4.5
In your question, the path to style is noted as Content/Earthlingtwo/style.css, where in your graphic it's Content/Earthlingtwo/images/style.css. In the Earthlingtwo folder, is a site.css file Content/Earthlingtwo/Site.css
You need to correct your href to the correct path
<link href="#Url.Content("~/Content/Earthlingtwo/images/style.css")"
rel="stylesheet" type="text/css" />
or
<link href="#Url.Content("~/Content/Earthlingtwo/Site.css")"
rel="stylesheet" type="text/css" />
depending on which is the correct file.