Some websites do not show Font Awesome icons when I access them

In my React project, I am utilizing the offline version of Font Awesome. I followed this manual to set it up. However, I am encountering an issue where the icons work on some pages but not on others. For instance, they display properly on localhost/courses but not on localhost/courses/1. A similar situation occurs with localhost/authors and localhost/authors/1. How can I resolve this problem? Here is how I implemented my current solution: I downloaded the offline bundle which includes multiple folders. I then referenced /css/all.css and /js/all.js inside the <head> tag.

<head>
  <link href="/folder/css/all.css" rel="stylesheet">
  <script defer src="/folder/js/all.js"></script>
</head>
<body>
  <i class="fas fa-user"></i> <!-- uses solid style -->
  <i class="far fa-user"></i> <!-- uses regular style -->
  <i class="fal fa-user"></i> <!-- uses light style -->
  <!--brand icon-->
  <i class="fab fa-github-square"></i> <!-- uses brands style -->
</body>

Answer №1

If you're looking for a solution, I've got one for you

One way to ensure safety is to use the full URL for your Font Awesome resources like this (or adjust accordingly if your URL differs from the one provided):

<head>
  <link href="//localhost/courses/folder/css/all.css" rel="stylesheet">
  <script defer src="//localhost/courses/folder/js/all.js"></script>
</head>
<body>
  <i class="fas fa-user"></i> <!-- uses solid style -->
  <i class="far fa-user"></i> <!-- uses regular style -->
  <i class="fal fa-user"></i> <!-- uses light style -->
  <!--brand icon-->
  <i class="fab fa-github-square"></i> <!-- uses brands style -->
</body>

Another option is to add ../ in your code, but make sure to adapt the structure based on the length of your URL:

<head>
  <link href="../folder/css/all.css" rel="stylesheet">
  <script defer src="../courses/folder/js/all.js"></script>
</head>

I believe this solution should work well for you.

Answer №2

To tackle this issue, I utilized React's %PUBLIC_URL% feature specifically designed for versions [email protected] and beyond. For further information on how to implement this feature, you can refer to the documentation provided here. In my current setup, I have made adjustments in referencing font-awesome files by storing them in a directory named font-awesome within the public folder of a React application.

<link type="text/css" rel="stylesheet" href="%PUBLIC_URL%/font-awesome/css/all.css">
<script defer src="%PUBLIC_URL%/font-awesome/js/all.js"></script>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Position of background image

Attempting to incorporate an image within a textbox in the following format (## representing the image): --------------------- | ## | --------------------- My progress so far: input.loading { background: url(/images/loader.gif) no ...

animate the alignment of right-aligned text to move to the right side and realign to the left

I need help with a small menu-list that should expand when the mouse is nearby. By default, the menu is aligned to the right, but on hover, every other item shifts to the left to accommodate the increased height (check out the JSFiddle). ul { font-siz ...

The dimensions of text that wraps itself around multiple lines are distinct from those of text that remains on a single line

Hello everyone, I need some assistance with setting up my WordPress blog. I have integrated both Facebook and native WordPress comments on my website: . My aim is to make the formatting of the WordPress comments resemble that of Facebook comments as closel ...

Ways to retrieve the parent component class within the child component

Is there a way to apply styles to the parent component class from within the child component using CSS in Angular 2? ...

Switching between fixed and unfixed divs causes two absolute divs to alternate

I am currently working on a code to keep a fixed div ("two") in place between two absolute positioned divs ("one" and "footer") while scrolling. However, there is an issue that arises when the browser window is resized. The distance between the footer and ...

The lengthy form on the page is overlapping with the footer

As someone with limited CSS/HTML skills and a preference for backend development, I decided to use a pre-made template. The default login page looks like this: https://i.sstatic.net/XKBAZ.png In the register-page that I customized based on the login pa ...

Steps for incorporating scrollIntoView in a horizontal testimonial table

I am sorry if the title has caused any confusion, but it is exactly as it states. I want to create a testimonial card using a table as the base. I have almost completed it, but I am struggling with the final touches. For instance, I want to implement a fun ...

How can you change a particular inline style using the Firefox browser?

I am looking for a solution to override an inline style on a specific webpage within the Firefox browser without access to the source code. Previously, I would manually modify the page source using Firefox development tools. Specifically, I encounter a we ...

Is there a way to adjust the size of text to perfectly fit within a fixed size div?

I find this scenario quite common, but I haven't come across any solutions for it: Let's say there is a fixed-width div that displays dynamically changing numbers. How can we adjust the font size so that larger numbers fit well within the fixed ...

Animating with Jquery swipe motion

I am looking to make my brand image appear animated when the site is opened. I want it to swipe or move linearly from left to right and then return to its original position. I tried searching on Google for a solution but couldn't figure out how to mak ...

What is the functionality of intro.js?

Currently, I am utilizing an onboarding tour at my.bonify.de that provides a similar experience to introjs. The way we have implemented this feature is quite unattractive, using a cutout div with a very large box-shadow. We are looking to enhance it by in ...

Struggling with aligning form-group elements along with razor html helper buttons in Bootstrap's form-horizontal layout

I'm struggling with properly aligning buttons in my razor markup. When using form-horizontal: <div class="row"> <div class="col-md-6"> <div class="form-group"> @html.labelfor @html.editorfor @html.validation ...

Is there a way to apply an indigo color solely to a div using CSS without affecting the entire body?

Can someone help me achieve a result similar to the image shown https://i.sstatic.net/IY1kI.png I've been working on some code, but I haven't been able to get the exact desired outcome. My goal is to make a div indigo and leave the rest of the b ...

Footer in Bootstrap 3 malfunctions if <h2> tag is missing

I've encountered a strange issue that I can't seem to figure out. Simply removing the <h2> tags in my code causes the footer to move to the top instead of the bottom. Oddly enough, the footer works perfectly when there is a title, but as so ...

Creating a Dynamic Navigation Bar using JavaScript

Hi everyone, I'm having some trouble with my sliding navigation bar. The issue I'm facing is how to change the tab images when sliding the bar out and back in (as shown in the image). I need the image for folding it back in to be inside the navig ...

The Jade template is not rendering the page correctly as anticipated

I'm working with Node.js & express, using the Jade template for the view. My issue is that the Test text is currently hidden under the black navigation bar. How can I move it to the bottom, below the navbar? What am I missing in my code? Here is the ...

The particles.js with absolute positioning is currently overlapping my div with relative positioning

Visit this link <div class="outer-container"> <div id="particles-js"> <div class="your-content"> <article id="3" class="bg-dusk transition md:group-hover:opacity-50 md:hover:opacity-important md:hov ...

Achieving a Transparent Flash overlay on a website without hindering its usability (attention, interaction, form submissions, etc.)

Currently, we are attempting to overlay a transparent flash on top of an iframe which loads external websites. Is there a method to configure the page in a way that allows the transparent flash to be displayed while still allowing interaction with the und ...

The parent font size is influenced by the font size of the child element

I am encountering an issue with my code that seems to be quite simple. Here is the code snippet: <p> <h3>Title is here</h3> This is the paragraph </p> Here is the CSS: h2 {font-size:2.3em;} h3 {font-size:1em;} p {font-size:0. ...

Create a function to allow the div to flash a different color temporarily upon being clicked

I've set up my website using divs as buttons, and when they're clicked they add ingredients to my burger. JS: <div id="ingredientBox"> <Ingredient ref="ingredient" v-for="item in currentIngredients" v-o ...