When I hover over the button, the Fontawesome arrow will shift its position

.b_btnWrapp .btn.btn_default:after {
  content: "\f054";
  font-family: 'Font Awesome 5 Free';
  font-weight: 900;
  position: absolute;
  top: 15px;
  right: 30px;
}

.b_btnWrapp .btn.btn_default:after:hover {
  content: "\f054";
  font-family: 'Font Awesome 5 Free';
  font-weight: 900;
  position: absolute;
  top: 15px;
  right: 18px;
}
<button class="b_btnWrapp btn btn_default">CLick</button>

I am looking to adjust the position of the arrow on the right side of the button by utilizing CSS and the AFTER concept.

Answer №1

To fix the issue with backspace causing confusion in a style selector, you need to adjust your code.

Try implementing the following code:

.b_btnWrapp {
  position: relative;
  width: 100px;
  height: 30px;
}

.b_btnWrapp:after {
   font-family: "Font Awesome 5 Free";
   content: "\f061";
  font-weight: 900;
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  right: 15px;
  transition: all .2s;
}

.b_btnWrapp:hover:after {
  right: 5px;
}
<!DOCTYPE html>
<html>

  <head>
    <link rel="stylesheet" href="style.css">
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">
    <script src="script.js"></script>
  </head>

  <body>
    <h1>Hello Plunker!</h1>
    <button class="b_btnWrapp btn btn_default">CLick</button>
  </body>

</html>

Additionally, I streamlined your code by eliminating unnecessary complexity and removing redundant parts. Remember to use position:relative on the parent element when positioning a child absolutely within its parent's coordinates. Pay attention to the order of selectors as well - .element:hover:after is different from .element:after:hover.

Answer №2

Consider incorporating this into your design

.b_btnWrapp.btn.btn_default:after {
      content: "\f054";
      font-family: 'Font Awesome 5 Free';
      font-weight: 900;
      position: absolute;
      top: 15px;
      right: 30px;
      cursor:pointer;
    }

    .b_btnWrapp.btn.btn_default:after:hover {
      top: 15px;
      right: 18px;
    }

Answer №3

Here is a simple Javascript code snippet to toggle the arrow icon using Font Awesome:

var icon=document.querySelector("#btn i");

function toggleArrow(){
  var isLeftArrow=icon.classList.contains("fa-chevron-left");
  if(isLeftArrow){
    icon.classList.add("fa-chevron-right");
    icon.classList.remove("fa-chevron-left");
  }else{
    icon.classList.add("fa-chevron-left");
    icon.classList.remove("fa-chevron-right");
  }
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/solid.css" integrity="sha384-r/k8YTFqmlOaqRkZuSiE9trsrDXkh07mRaoGBMoDcmA58OHILZPsk29i2BsFng1B" crossorigin="anonymous">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/fontawesome.css" integrity="sha384-4aon80D8rXCGx9ayDt85LbyUHeMWd3UiBaWliBlJ53yzm9hqN21A+o1pqoyK04h+" crossorigin="anonymous">

<button id="btn" class="b_btnWrapp btn btn_default" onclick="toggleArrow()">
  Click 
  <i class="fas fa-chevron-left"></i>
</button>

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

Include a basic downward-pointing arrow graphic to enhance the drop-down navigation menus

I am working on a website that has drop-down menu headings styled with CSS. I am looking to enhance these certain menu headers by adding small down-facing arrows indicating they are clickable. Does anyone have any suggestions on how I can achieve this? ...

Activate and deactivate animation using one button with jQuery

Looking for a solution using Jquery. Can you animate an element when clicking a button and then stop the animation with the same button? Here is an example code snippet in JavaScript: $('<div>').css({ 'width':'200 ...

Extracting Values from JSON Array using Form Input Text

After designing a form for my web application, I encountered a situation where some fields needed to be populated with values from a JSON array retrieved from the treatment table in the database. {"treatment":[ { "id" : 1, "name" : "Leg Training" }, ...

Should tabs be closed or redirected after successful authentication with Google?

I have a project that was developed using perl-dancer and angular. The project is integrated with Google as an openID system. On some of the pages, there is an edit grid with a save button. To prevent loss of unsaved data when the session (created from pe ...

The tree expansion does not activate the CSS transition

Currently, I am in the process of creating a TreeView using only CSS and JS. My goal is to include a subtle transition effect when expanding or collapsing a node. The transition effects are successfully implemented for collapsing nodes, however, they do no ...

What is the best method for sending a user to a different page when a webhook is triggered by an external API in

In my project using NextJS and the pages router, I encounter a scenario where a user initiates a process through a form that takes approximately 30 seconds to complete. This process is carried out by an external API over which I have no control. Once the p ...

Codepen for showcasing your Javascript and Jquery skills

I'm having a bit of trouble with the .getjson function. I've been working on retrieving data from a Wikipedia API using .getjson, and while everything seems to be working fine, there's a peculiar issue when I try to find the length of an arr ...

Localizing Dates in JavaScript

I'm currently dealing with localization and globalization in an ASP.NET application. As I navigate through this process, I am encountering difficulties in getting the Date() function in JavaScript to function correctly based on the user's locatio ...

I am facing an issue with my Angular 11 CLI application while trying to set it up with Jest. The specific error message I am encountering is: "TypeError: Cannot read property

Having issues with my Angular 11 cli app and Jest integration. Whenever I run npm run test, specifically jest --updateSnapshot, I encounter the following error in my terminal: Error: TypeError: Cannot read property 'paths' of undefined Here is ...

Implement a callback function in React using hooks after changing the state

Back in the days of React before hooks, setting state and calling a function after it had been set was achieved using the following syntax: this.setState({}, () => {//Callback}) Now, with hooks, what is the equivalent way to achieve this? I attempted ...

I am looking to have two elements positioned next to each other in equal dimensions, such as the reCaptcha feature

Could someone assist me in positioning these elements side by side, each taking up 50% of the screen? I'm unsure if this can be achieved while using the reCaptcha iFrame. <div class="g-recaptcha" data-sitekey="sitekey" style="transform:scale(0.5); ...

"Upgrade your upload experience with Express Upload - easily switch out images in a folder while simultaneously

As I work on incorporating a profile picture feature into my website, I am encountering an issue where a newly uploaded image [newimg] with the same name as a previously uploaded image [oldimg] ends up replacing the older file in my directory. This results ...

Updating View in Angular 2 ngClass Issue

I'm encountering some challenges with updating my view using ngClass despite the back end updating correctly. Below is my controller: @Component({ selector: 'show-hide-table', template: ' <table> <thead> ...

Using bootstrap-vue sticky columns without specifying a column variant is easier than you think

Let's cut to the chase with an example I created using bootstrap-vue's documentation to help clarify the issue: <template> <div> <div class="mb-2"> <b-form-checkbox v-model="stickyHeader" inline>Sticky header& ...

Activate the toggle feature on the navigation bar using Bootstrap

Below is the code I am using: <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8defe2e2f9fef9ffecfdcdb8a3bda3bf">[email protected]</a>/dist/css/bootstrap.min.css" rel ...

Issue with JQuery timepicker not displaying on screen

Has anyone encountered a similar issue to mine? I am trying to implement the Simple init DateTimePicker from this example. Here is the code for my simple PHP page: <html> <head> <script src="js/jquery.js"></script> <script src=" ...

The implementation of CSS in one React component has an impact on the functionality of the Ant Design Select component in

I've run into a puzzling issue where importing CSS styles in one React component is impacting the appearance of Ant Design's Select component in another component. Let me break down the scenario: The setup involves two React components, namely P ...

How can I align the menu to the right in the navbar using Bootstrap 4?

I'm currently customizing the Bootstrap 4 default navbar and I want to add a collapsing menu that is positioned on the right, instead of the left, when it's not collapsed. So far, I have attempted to use text-right and float-right, but unfortuna ...

Creating a mask overlay that covers the entire screen while excluding a specific sibling div

My goal is to create a div that acts as a mask covering the entire window. It should have an opacity of 0.5 and a background color of lightgray. However, there is one particular div on the screen that I do not want to be affected by the mask. I attempted t ...

Dynamic assignment of NgModel in AngularJSIs it possible to dynamically

In my controller, there is an array named fields with a specific structure. Here is an example of the data within the array: [ { "name": "Demarcación", "type": "multiple", "scope": "restricted", "icon": "location-arrow ...