Can the @font-face src URL be modified?

We have integrated FontAwesome with Bootstrap on our website. However, we encountered an issue when using FA with a custom minifier as it tries to load fonts from a relative path, leading to a 404 error due to the structure of the minified URL.

To address this, we decided to include an additional CSS file in our minify list that would override the @font-face src URLs used by FontAwesome's font. We essentially copied the @font-face definition from FontAwesome and specified absolute URL locations.

Despite implementing this solution, we now face a situation where both the correct URLs and the original URLs specified in the FontAwesome CSS are being attempted to be loaded, resulting in recurring 404 errors.

Is there something we are missing or is it not possible to completely ignore the 'upstream' definitions and only use the overriding @font-face src URLs?

Answer №1

To change the font-family of the default CSS class, follow these steps:

.fa {
  font-family: 'AwesomeIcons' !important;
}

After that, insert and adjust the font definition code:

@font-face {
  font-family: 'AwesomeIcons';
  src: url('//subdomain.domain/yourdirectory/font-awesome-icons.eot?v=4.2.2');
  ...
  font-style: normal;
}

Answer №2

UPDATE: Despite attempting the suggested "solution," it unfortunately did not resolve the issue. While a typo was initially identified, further testing revealed that it was not the root cause of our problem.

To avoid encountering similar issues when overriding the @font-face, it is crucial to ensure that all formats used in the original @font-face declaration are correctly provided. Failure to do so may result in the browser interpreting it as a separate definition and attempting to download files referenced in both declarations instead of simply overriding them.

Here is the original @font-face definition from FontAwesome's CSS:

@font-face {
  font-family: 'FontAwesome';
  src: url('../font/fontawesome-webfont.eot?v=3.1.0');
  src: url('../font/fontawesome-webfont.eot?#iefix&v=3.1.0') format('embedded-opentype'), 
    url('../font/fontawesome-webfont.woff?v=3.1.0') format('woff'), 
    url('../font/fontawesome-webfont.ttf?v=3.1.0') format('truetype'), 
    url('../font/fontawesome-webfont.svg#fontawesomeregular?v=3.1.0') format('svg');
  font-weight: normal;
  font-style: normal;
}

When attempting to override this declaration, we mistakenly omitted the "format('svg')" specification:

@font-face {
  font-family: 'FontAwesome';
  src: url('//ourdomain.com/includes/font-awesome-3.1.x/font/fontawesome-webfont.eot?v=3.0.1');
  src: url('//ourdomain.com/includes/font-awesome-3.1.x/font/fontawesome-webfont.eot?#iefix&v=3.0.1') format('embedded-opentype'),
    url('//ourdomain.com/includes/font-awesome-3.1.x/font/fontawesome-webfont.woff?v=3.0.1') format('woff'),
    url('//ourdomain.com/includes/font-awesome-3.1.x/font/fontawesome-webfont.ttf?v=3.0.1') format('truetype');
  font-weight: normal;
  font-style: normal;
}

Upon rectifying this by adding the format('truetype') specification, we were able to eliminate the unnecessary requests that were leading to 404 errors.

Answer №3

If you are working with SCSS, chances are you have a primary scss file located in the src directory that includes an @import "font-awesome" statement to import font-awesome from node_modules/font-awesome/scss/font-awesome.scss.

You have the option to copy the font-awesome.scss file to your src directory and make modifications to it. Additionally, you can also duplicate the font-awesome/scss/path.scss file to your src folder for further customization.

In your main.scss (or whatever your initial scss file is named)

@import "path/custom-fontawesome";

Within custom-fontawesome.scss

@import "~font-awesome/scss/variables";
@import "~font-awesome/scss/mixins";
@import "custom-fontawesome-path";
@import "~font-awesome/scss/core";
..(additional imports)
@import "~font-awesome/scss/screen-reader";

Inside custom-fontawesome-path.scss

$fa-font-path: "../fonts-path";

@font-face {
  font-family: 'FontAwesome';
  src: url('#{$fa-font-path}/fontawesome-webfont.woff2?v=#{$fa-version}') format('woff2');
  font-weight: normal;
  font-style: normal;
}

You have the flexibility to customize the path to the font files by adjusting the

$fa-font-path: "../fonts-path";

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

Encountering an unexpected token error while attempting to incorporate JQuery into a React JS project

I am currently diving into the world of React.js and attempting to incorporate a side navigation bar on my homepage. However, I encountered an eslint error when trying to implement the sidebar using jQuery code. Below you will find the code snippet for the ...

Ways to make the Select component in Material-UI lose its focus state once an item has been selected

Anticipated outcome: Upon selecting an item, the Menu list will promptly close, and the Select component will no longer display a focus state. The borderBottom will change to 1px solid, and the backgroundColor will turn to white. Current situation: Sele ...

ScrollReveal.js won't function as intended

https://i.stack.imgur.com/SOQEk.png Looking to utilize the popular ScrollReveal.js created by Julian Lloyd (ScrollReveal) Despite following instructions from various sources, the script is not producing the intended effect. Steps taken to make it work: ...

The process of enriching an ASP.NET hyperlink by making it both bold and under

I'm currently working on a webpage in asp.net. I have two hyperlinks and I want to make them active by applying a style sheet that makes them bolder and underlined, but for some reason it's not working. Here is the HTML: <li style="margin-le ...

Tips for maintaining the nested collapsible table row within the main table row in a React MUI table

I am working on implementing a Material UI (MUI) table that includes collapsible table rows. The challenge I am facing is maintaining consistent border and background colors across all the rows, even when some are collapsed. Currently, the separate rows ar ...

Break apart animation similar to the 🎊 emoji using CSS styling

I am attempting to create an animation of a circle splitting open on two sides, similar to the ...

Is it possible to accomplish this straightforward task using PHP?

Essentially, my goal is to have the content inside the h1 tag duplicated in the h2 tag as well. Take a look at the example provided below. <!DOCTYPE html> <html> <body> <h1>The content here should also appear in the H2 tag.</h1 ...

Retrieve numerical data from the element and enclose it within a span tag

My goal was to indent a number, but the HTML generated from my CMS is making it difficult to target the number and apply a specific style. <div class="content"> <b>01. Header</b> Lorem ipsum dolor sit amet, consectetur adipisicing elit, ...

Sending information to the styles feature in Angular 2

Is there a way to transfer data from an Angular tag to the styles in the @Component? Take a look at my component: import { Component, Input } from '@angular/core'; @Component({ selector: 'icon', template: `<svg class="icon"> ...

The sidebar vanishes when you move your cursor over the text contained within

My issue is that the side menu keeps closing when I hover over the text inside it. The "About" text functions correctly, but the other three don't seem to work as intended. Despite trying various solutions, I am unable to identify the root cause of th ...

Initiating a horizontal scroll menu at the center of the screen: Step-by

I need assistance setting up a horizontal scrolling menu for my project. The requirement is to position the middle button in the center of the .scrollmenu div. Currently, I am working with HTML and CSS, but open to suggestions involving javascript as well ...

JavaScript encoding and decoding challenges

Can anyone help me figure out what's wrong? I'm trying to encode and decode a simple input, but it just doesn't seem to work! Any ideas why? Thanks in advance for your assistance :) ENCODE: function encryption_encode(s, delta) { var te ...

Ensure child elements do not surpass parent size in HTML/CSS/Javascript without altering the children directly

I am intrigued by how iframes neatly encapsulate all site data within a frame and adjust it to fit the size. Is there any method to achieve this functionality in an HTML wrapper? Can the wrapper be configured so that regardless of the content, it is dis ...

Is there a more efficient approach to applying a basic function to multiple elements within a DIV and having it activate only upon a click event using jQuery?

This solution works, but I am looking for a more professional approach in order to adhere to the principle of "don't repeat yourself." $("document").ready(function(){ $(".child").each(function(index){ $(this).click(func ...

jQuery can be used to relocate buttons on a webpage

When the Contact button is clicked, how can I move the Close button below #panel? It's currently fixed in position. Here's my demonstration: https://jsfiddle.net/25u78gff/ https://i.sstatic.net/qDad9.png jQuery('.sub-menu').addClass( ...

Ways to position the second section below the button

Is there a way to make a section of my website where, upon pressing a button, the button moves to the left and reveals collapsed text that appears below it with some padding on top? I've been trying to achieve this as a beginner by looking through doc ...

The ion-item is refusing to be centered on the page

I'm having trouble centering an ion-item and it seems slightly off-center. The standard methods like text-align: center and adjusting padding in ion-content don't seem to be working for me. Can someone please assist? https://i.stack.imgur.com/QZ ...

Element in list displaying a distinct alignment from the rest

I currently have a navigation bar based on a list, which looks something like this: https://i.stack.imgur.com/e1Dmb.png My concern is how to position the "Logout" item on the right side of the screen. I've tried adding clear list items but that seem ...

Comparing React's Styled-components, JSS, and Emotion: Which is

As a CTO, I am faced with the decision of choosing between three popular CSS-in-JS libraries: jss emotion styled-component. I will keep this question focused and avoid straying into subjective territory. If necessary, I will answer it myself by asking sp ...

Center flex items along the vertical axis

IMAGE <div className="d-flex align-items-center"> <img src={member.user_profile_image} width="41" height="41" alt="" ...