Stylish CSS Tricks with Font Awesome Icons

In my project, I am utilizing Font Awesome SVG with JavaScript multiple times. Currently, I am working on creating a button that displays an arrow icon to the right of the text when hovered over. However, I encountered an issue where there is a blank square instead of the icon appearing in the designated spot.

To address this issue, I used:

display:none 

This solution successfully got rid of the empty icon on the right side of the button text. But now, I want to know how I can make the icon appear within the blank square.

The code snippet is as follows:

window.FontAwesomeConfig = {
        searchPseudoElements: true
}
.fa-arrow-right:before {
    font-family: 'Font Awesome 5 Solid';
    content: "\f061";
    font-weight: 900;

}


 .btn-4 {
    border-radius: 50px;
    border: 3px solid #fff;
    color: #fff;
    overflow: hidden;
}

.btn-4:active {
    border-color: #17954c;
    color: #17954c;
}

/* Button styles and animations */

I have captured screenshots to better illustrate the problem: buttons and buttons on hover

Answer №1

Utilizing font-awesome requires specifying the font-family and including the awesome font cheatsheet in the content.

Font-family:

font-family: FontAwesome;

Content:

content: '/f2bb' // example

Cheatsheet - https://fontawesome.com/cheatsheet

h1 {
  margin: 25px auto;
  font-size: 40px;
  text-align: center;
  font-family: sans-serif;
}

.box {
  width: 150px;
  height: 150px;
  background-color: #CD5C5C;
  margin: 0 auto;
  position: relative;
}

.box::after {
  content: "\f0fc";
  font-family: FontAwesome;
  font-size: 100px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
<head>
  <meta charset="UTF-8">
  <title>Font Awesome With Pseudo-Elements</title>
<!--  Font Awesome 4.6.3 CDN  -->
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css">
</head>
<body>
  <h1>Font Awesome with Pseudo-Elements</h1>
  <div class="box"></div>
</body>

Answer №2

Don't forget to include the fa class in addition to the fa-arrow-right class.

Be sure to eliminate any unnecessary styles that have been added.

.fa-arrow-right:before {
    font-family: 'Font Awesome 5 Solid';
    content: "\f061";
    font-weight: 900;
}

Using the fa class will handle all of this for you.

I hope that explanation helps.

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

Why isn't my HTML reflecting the CSS changes I've made?

My CSS code is not applying to the HTML in general, only to h1 and h3. I have used similar looking code before and it worked fine. html { text-align:center; border:25px dotted #ff5c33; background-color:#00b300; color:#ff5c33; font-fami ...

Utilizing a variety of textures across various surfaces of a single geometry

I'm new to working with Three.js and I have a question about displaying multiple images over a plane geometry. Here is the scenario: Imagine a simplified case where we have a plane divided into tiles like this: +---+---+---+ | 1 | 2 | 3 | +---+- ...

DataGrid React MUI: Aligning Column Data and Header for "Number" Type

In my React project, I am using MUI. I noticed that when I specify the type of a column as type: "number", both the column header and data align to the right. This issue can be replicated in a simple example taken from the MUI documentation: code ...

Using jQuery to iterate through JSON data obtained from a web service

In this code snippet, I am attempting to retrieve a JSON response from a PHP page and then iterate through it to display the name field of each JSON object. However, for some reason, nothing is being alerted out. <html> <head> <title>A ...

Is there a way to utilize a Bootstrap Card and Django for loop to upload an image?

Trying to upload an image using Django within a Bootstrap Card loop, but facing an issue. Models.py and views.py code has been added: The problem is that images are not showing up in the browser, while other details like name and price are loading correct ...

Connecting Ag Grid with modules

Unable to link with modules as it's not a recognized attribute of ag-grid-angular https://i.sstatic.net/2zwY2.png <ag-grid-angular #agGrid style="width: 100%; height: 100%;" id="myGrid" class="ag-theme-balham" [mod ...

Tips for hiding an HTML tag with specific attributes from showing up in Google Chrome

Lately, I've been using a handy extension called Stylish on Google Chrome to block those annoying ads and other unwanted elements from popping up. It's quite simple - all you need is the class name or id of the tag, and you can make it disappear ...

Ways to position one card to the lower left corner of another card on separate screens

Hello, I am at the beginning of my journey into Web development, and I have successfully created a basic HTML webpage using bootstrap-4. My goal is to have 2 cards displayed horizontally, with the image card on the left and the text card on the right. Whe ...

PHP function with JSON response encountered an error during the AJAX call

I am currently working on creating a News Ticker that utilizes PHP, Javascript, and AJAX. The first step involved creating a PHP function called getFeed(), which gathers data from various news websites into an Array. This data is then returned in JSON form ...

New and improved Bootstrap 5 menu bar

I am seeking to customize my navigation bar by adding a black background that spans its entire length. I do not want to rearrange the links or logo; just apply a background color. Another issue arises during SASS compilation: I am trying to change the col ...

Tips for deleting a text node preceding a div element?

Here's the HTML code snippet I am currently working with: <div id="wrapper"> <div id="some-id"></div> "this is some texxt" <div id="some-id-2"></div> </div> Is there a way to eliminate the text using CSS? ...

Google Maps autocomplete feature is causing the input to update only after clicking in ng-model

After fetching a Google Maps place ID from a REST API, I utilize the Google Maps API to retrieve the place object in this manner: var geocoder = new google.maps.Geocoder; geocoder.geocode({ 'placeId': data.city }, fun ...

Modify the name format using an AngularJS directive

I've been struggling to understand how to effectively write AngularJS directives, even after reading various blogs. The issue I am facing is with an array of names in the format "lastname, firstname". My goal is to create a directive that will display ...

Angular2+ allows users to easily drag and drop an image onto the screen, complete with

Check out this stackblitz link for more details: https://stackblitz.com/edit/angular6-ledera?file=app%2Fapp.component.ts I'm attempting to drag an image from the desktop and drop it directly onto the dropzone div. 1) Obtain a preview of the image 2) ...

Tips on obtaining the element selector when a div is being dynamically loaded during an AJAX call

When running two ajax calls, I encounter an issue where the second call loads some HTML onto the page that is needed for processing a specific div in the first call. However, since the div is not present until after the second call is completed, I receiv ...

Creating an HTML button that functions as a link to a specific section on the same page

I am interested in creating an HTML button that functions as a link to an item on the same page. Essentially, when this button is clicked, it should redirect to an item within the same page. Is there a way to achieve this using only HTML, CSS, and JavaScr ...

Does Three.js come with a default function for generating heightmaps?

Currently, I am engrossed in developing a JavaScript game using Three.js. My interest lies in enhancing the realism of the walls by incorporating a height map (refer to the provided image). View this snapshot of the game design featuring a 2D wall. All th ...

Issue with the height of Bootstrap 4 navigation bar

After deciding to use Bootstrap 4 for my current project, I encountered an issue with the navbar. It seems to expand too much, which is only happening once I deploy the website. Can anyone help me figure out what's causing this problem? Below is the c ...

The max-width attribute is ineffective for descendants of the flexbox item

When setting display:Flex to the .container element and placing two children within, I attempted to give a max-width to the second flex-Item child (.box), but it seems to not be working as expected. body { font-family: sans-serif } .container { dis ...

Error: Vue is unable to access the property '_modulesNamespaceMap' because it is undefined

I've been working on a simple web app to enhance my testing skills in Vue using Vue Test Utils and Jest. However, I encountered an error related to Vue while trying to console log and check if AddDialog is present in my Home file. The error message I ...