icon from font-awesome changes color when hovering over

My ASP.NET gridview control includes a font-awesome trash icon in the last column.

I'm trying to make the icon change color to red when I hover over it, and then revert back to its default color when I move my mouse away.

Here is the code for the template field within the ASP.NET gridview:

<asp:TemplateField HeaderText="Delete?" ItemStyle-HorizontalAlign="Center">
    <ItemTemplate>
        <span ID="lnkDelete" style="border:none" onclick="return confirm('Are you sure you want to delete this Performance Review?')"
                    runat="server" ItemStyle-CssClass="fa fa-trash-0" 
                onmouseover="this.style='color:red;'"    
                CommandName="Delete">
                <i  class="fa fa-trash-o" onmouseover="script:this.style='color:red; font-size:24px'"  onmouseout="script:this.style='color:black; font-size:24px'"
                    style="font-size:24px;"></i> 
            </span>

    </ItemTemplate>
</asp:TemplateField>

When rendered in IE, it looks like this:

<span id="ctl00_m_g_10488b48_1486_45be_8a9c_efc307c0cb4b_ctl00_grdPR_ctl04_lnkDelete" style="border: currentColor;" 
onclick="return confirm('Are you sure you want to delete this Performance Review?')" CommandName="Delete" ItemStyle-CssClass="fa fa-trash-0">
<i class="fa fa-trash-o" style="font-size: 24px;" onmouseover="script:this.style='color:red; font-size:24px'"></i> 
                    </span>

Despite my efforts, the color doesn't change when I hover over the trash can icon.

I've also attempted using CSS hover styles on my page, but that didn't work either:

<style>
.fa fa-trash-o{
  color: black
}
.fa fa-trash-o:hover{
  color:red;
}
</style>

Can anyone help me figure out what I'm doing wrong?

Answer №1

To achieve this effect, CSS alone can be used. The issue lies in using the incorrect selector in the CSS code. Both the classes fa and fa-trash-o are applied to the same element. Therefore, the space between fa and fa-trash-o needs to be removed, and a period . should be placed before them since they are classes.

.fa.fa-trash-o {
  color: black
}

.fa.fa-trash-o:hover {
  color: red;
}
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
<i class="fa fa-trash-o"></i>

Answer №2

Don't forget to include a . before the fa-trash-o class in your CSS selector:
Check out this resource for more information on CSS selectors: https://www.w3schools.com/cssref/css_selectors.asp

.fa-trash-o{
  color: black
}
.fa-trash-o:hover{
  color:red;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<span>
    <i class="fa fa-trash-o" style="font-size: 24px;"></i> 
</span>

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

Employ the power of AJAX to selectively display or conceal a specific group of images

Have you ever thought about showcasing a large number of images on a non-CMS website? Say you have 50 images that can't all be displayed at once. One idea is to display the first 15, then allow users to click "Next" to reveal the next batch of 15, and ...

Bootstrap image with simplistic arrow indicators

I'm facing a minor issue that I need help solving. I want to have two simple arrows (one pointing left and one right) vertically aligned in the center of an image. Additionally, these arrows should resize proportionally when the screen size changes. ...

What is the regular expression to match a specific amount of digits followed by exactly one hyphen?

After creating the regex below: (\d{5}|\d-\d{4}|\d{2}-\d{3}|\d{3}-\d{2}|\d{4}-\d) It appears to function as intended. This regex will find a 5 digit number or a 5 digit number with a single hyphen embedded wit ...

Using Data URIs can negatively impact the loading speed of a webpage

I created a custom script to replace all inline images with data URIs in order to minimize http requests and speed up loading times on mobile devices. Surprisingly, I noticed a decrease in loading speed. Could it be because the HTML file was larger (aroun ...

I am looking to place two HTML buttons next to each other on the same line

I am trying to display two HTML buttons next to each other on the same line, with the "Submit Request(s)" button appearing first. The issue I am facing is that the top of the second button aligns with the bottom of the first one. The second button is cor ...

I'm having trouble connecting my CSS file to my HTML file. It seems to be functioning properly with Live Server, but it's not working on its own. Any ideas on what

Recently, I encountered an issue with my CSS and HTML files. Initially, they were in the same folder on my desktop and the <link rel="stylesheet" type="text/css" href="style.css" /> reference worked perfectly. However, I decided to organize my file ...

Instructions on How to Populate a Textbox with Data in ASPX

Is there a way to efficiently display the query output in a textbox named "Textbox1"? <%@ page language="C#" autoeventwireup="true" codeBehind="Default.aspx.cs" inherits="MainPage, App_Web_rlctbjj5" %> <%@ Import Namespace="System.Data" %> & ...

Leveraging jQuery's .animate method to create engaging search box animations

Greetings esteemed individuals... I am currently working on enhancing the search component for my application... http://jsfiddle.net/SkyKOG/K8utq/24/ input{ display:none; width:0px; color:#999; } Initially, I only had a simple search box so ...

Determine the dimensions of child components within Svelte templates

I am currently in the process of transitioning a VanillaJS website to Svelte, and I need to have divs randomly positioned on the webpage. It's important to note that each div's size can vary depending on its content, so they cannot have a fixed s ...

Adding CSS files to a JSP page in Spring MVC

This is how my project's structure looks like: webapp: resources: css: test.css WEB-INF: pages: mvc-dispatcher-servlet.xml web.xml I am working on including a .css file in my jsp. mv ...

JavaScript effectively divides multiple child dropdowns with the main dropdown, thanks to Bootstrap innovation

I have implemented a jQuery function to dynamically change multiple child dropdowns based on the selected value of the main dropdown. For reference, you can view the image here. However, I encountered an issue when applying the Bootstrap styles "form-con ...

Managing multiple sessions for a single website on the same browser through various tabs in ASP.net C# - A comprehensive guide

What is the best way to manage multiple sessions for a single website when using the same browser with different tabs in ASP.net C#? For example, similar to Google where opening 2 accounts in the same browser does not impact user details. ...

Guide to designing a dropdown navigation menu in GWT

Hey, I'm currently working on setting up a drop down menu using GWT and here's the layout I have in mind: | Categories | Pictures | Other | When the categories dropdown opens, my goal is to display the categories grouped in pairs. For example: ...

Tips for eliminating flicker upon the initial loading of a webpage caused by dynamic changes in CSS styles through JavaScript

Struggling with the load order of my CSS and JavaScript... Currently, I have a div with a blue background that is styled to appear sliced diagonally. However, upon initial page load (or CTRL+SHIFT+R), there's a brief moment where the slice effect doe ...

What is the best way to ensure a div takes up the rest of the height on a page when the header's size is unpredictable

Is there a way to make the red area fill the remaining visible space without overlapping into the footer? I also need the infoContent section to be scrollable. The height of the header may vary. I came across some older solutions that suggested using Java ...

Server-side execution of jQuery and HTML components

In the user control (header), there is a div containing different sub divs. One of these sub divs includes user options, displaying the username of the logged-in user and links for logout, settings, etc. This "user_options" div is positioned absolutely wit ...

"Having trouble with the countdown timer in asp.net/jquery - it's

Below is the complete code: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt ...

The completion of the ExecuteNonQuery process encountered an error

There seems to be an error in the button click event. I am receiving an error message specifically on this line: com.EndExecuteNonQuery(); The error message reads: Error 2 No overload for method 'EndExecuteNonQuery' takes 0 arguments Thank you ...

Trouble with the query waypoints extension in a simple demonstration

Can anyone help me figure out why the basic example from the waypoints plugin isn't working for me? Here's a link to the jsfiddle I created: http://jsfiddle.net/ZA8bd/2/ CSS .block1 { margin-top:30px; width: 400px; background: red; ...

Designing a drop-down menu that appears visually above its parent

As I design a menu positioned at the bottom using position:absolute; bottom:0, I want the submenu items to align perfectly above their parent. Each li should appear above the ul itself. The trick to achieving this is by applying a negative margin. However ...