When using Angular with font awesome icons as content in CSS, it displays as a square box

After thorough research, I have come to seek help with an issue in my angular project. I am using ng-select and attempting to replace the default dropdown icon with one from font-awesome.

To integrate font-awesome into my project, I followed these steps:

ng add @fortawesome/angular-fontawesome
npm install @fortawesome/free-solid-svg-icons

In my CSS, I tried to change the ng-select dropdown icon using the following code:

.ng-select ::ng-deep .ng-arrow-wrapper .ng-arrow {
  display: none;
}

.ng-select ::ng-deep span.ng-arrow-wrapper::before {
  font-family: 'Font Awesome 5 Free';
  font-weight: 900;
  content: '\f078';
}

The result is shown below

https://i.sstatic.net/rhCEU.png

I welcome any suggestions or insights. You can view my StackBlitz here: https://stackblitz.com/edit/angular-yrhnot?file=src/app/app.component.css

Answer №1

Proper technique for incorporating Font Awesome icons using the CSS content property.

.icon::before {
    display: inline-block;
    font-style: normal;
    font-variant: normal;
    text-rendering: auto;
    -webkit-font-smoothing: antialiased;
  }

  .login::before {
    font-family: "Font Awesome 5 Free"; font-weight: 900; content: "\f007";
  }
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" rel="stylesheet"/>

<ul style="margin: 0;">
  <li><span class="icon login"></span> <- Login Icon</li>
</ul>

Ensure that you have adhered to this format and verify the correct Unicode codepoints you are including in content

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

Set up four divs in a cascading arrangement across four separate columns

Looking to set up 4 cascading divs that create the appearance of being in 4 columns. Here is the given html structure (unable to be modified) <div class="col1"> 1111 <div class="col2"> 2222 <div cl ...

Configuring static files in Django for hosting a website in production mode

I have been attempting to serve my static files from the same production site in a different way. Here are the steps I took: First, I updated the settings.py file with the following: DEBUG = False ALLOWED_HOSTS = ['12.10.100.11', 'localhos ...

Encountering an issue with receiving incorrect values when subscribing in Angular

Looking at this function that checks for the existence of a code in the database: isCodeExist(code: string): Observable < boolean > { return <Observable < boolean >> this.afs .collection(this.jobsCollection, ref => ref .wh ...

Implementing a Tri-state Checkbox in AngularJS

I've come across various discussions on implementing a 3-state checkbox with a directive or using CSS tricks (such as setting 'indeterminate=true' which doesn't seem to work). However, I'm curious if there's another method to ...

Sending a Nan alert regarding a JSON attribute

I recently completed a project using Angular4 that involves connecting to a nodeExpressJS server to retrieve JSON data and update the object with new information. Below is the onSubmit function from the addemployeeform. onSubmit(formValue: any) { cons ...

When is the ideal moment to utilize SASS extensions?

My current team uses SASS and I've noticed that we're extending very simple styles in our code. I fail to see the purpose of doing this. Am I overlooking something? Below are some examples of styles from a _Common.scss file that is imported and ...

Can Glychicons be utilized in form submission buttons?

While I can easily create buttons with glyphicons using the <a class="btn...", I'm facing an issue when trying to do the same with <input type="submit" class="btn btn-default" value="" />. Instead of displaying the button, it appears blank. ...

What is the best way to hide a div when an image is positioned on top of it?

Previously, I inquired about creating a "cursor mirror" where the movement of the cursor in the top section of a website would be mirrored in the opposite direction in the bottom section. You can find the original question here. Expanding on that concept, ...

Struggling to connect CSS files to an HTML document

Could someone lend a hand in figuring out why this link isn't working as expected? I've attempted to adjust margins within the .banner class, but it doesn't seem to be making any difference. I'm also worried because Atom doesn't s ...

Creating a customized file input using CSS

I am currently utilizing Bootstrap4 to craft my webpage and I am incorporating a custom file input bar. To retrieve the three labels of the input bar ("Choose file", "Browse", "Upload") from my stylesheet, I have created three custom classes with their co ...

Modify the width of the inner or child elements

My parent container can contain either 1, 2, or 3 child elements. When there is only one child element, it should take up 100% of the width. If there are two child elements, they should each have 50% of the available width. And if there are three child e ...

Formatting Text in CSS and HTML

I need help aligning three images horizontally with text underneath, using CSS. Despite trying multiple methods, the images remain vertically aligned and the text does not align properly with the images. #img_cont { display: table; width: 90%; ...

Tips for transferring data when clicking in Angular 5 from the parent component to the child component

I need assistance with passing data from a parent component to a child component in Angular 5. I want the child component to render as a separate page instead of within the parent's template. For example, let's say my child component is called & ...

"Encountering issue with SCSS variable not being applied to background in file

$enable-grid-classes: false; $enable-cssgrid:true; $deepBlue: #032f3e; body { --bs-body-bg: orange ; } @import "https://fonts.googleapis.com/css2?family=Space+Grotesk:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="463121 ...

Tips for chaining API calls in Angular using rxjs?

How can I efficiently nest API calls in Angular using RxJS? getProducts(): Observable<any> { return this.getProductIDs().pipe( map((response) => response.products.map((data) => (item: any) => flatMap(() => th ...

avoid displaying 500 error in the developer console upon catching an exception

Currently, I am working in an Angular 2 front-end environment with Node.js as the backend. One of my component classes is making calls to a DataService that communicates with the Node backend. Unfortunately, when the Node backend returns a 500 error for er ...

There seems to be an issue with the subscription of a subject between two modules in Angular 5

Currently, I am in the process of developing a project using Angular 5. One requirement is to display an app loading spinner frequently. To achieve this, I have created a shared module along with a spinner component within it. Below is the content of my mo ...

There seems to be an issue with locating a differ that supports the object '[object Object]' of type 'object'. NgFor is only compatible with binding to Iterables like Arrays

My route.js const express = require('express'); const router = express.Router(); const University = require('../models/university'); var mongo = require('mongodb').MongoClient; var assert = require('assert'); va ...

Arrangement of images in an array

Here's the scenario I'm facing. https://i.stack.imgur.com/FbAfw.jpg So, I have an array of images that I want to use to create a gallery with a specific layout. I've tried using grid and playing around with :nth-child(even) and :nth-child( ...

Is there a way to use HTML and CSS to switch the style of a dynamic decimal number to either Roman numerals or Katakana characters within a specified HTML element, such as a tag, div

I've searched everywhere but only found guides on list styling and counter styling in CSS that didn't work out. So, for example, I have a number inside an HTML tag that is changed dynamically using Vue Watch. I want to display the number in upper ...