Tips for customizing icons when hovering in CSS

I'm trying to make a default icon light up on hover using CSS, but I'm having trouble getting it to work. Any suggestions on how I can achieve this effect? Thank you!

HTML

<ul class='nav nav-main nav-sidebar'>
 <li role='presentation'>
   <a href='javascript:void(0)'>
    <i class='pull-left fu fu-lg fu-parents'></i>
    Parents
</a>

CSS

li {
    .hidden-on-hover {
        display: inherit;
    }
    .visible-on-hover {
        display: none;
    }
}
li:hover {
    .hidden-on-hover {
        display: none;
    }
    .visible-on-hover {
        display: inherit;
    }
    i.fu.fu-parents {
        background: image_url("icons/navigation/default/parents.svg") center center no-repeat;
        background-size: contain
    }
    i.fu.fu-parents.active {
        background: image_url("icons/navigation/active/parents-active.svg") center center no-repeat;
        background-size: contain
    }
}

Answer №1

Your styles are not being applied to the :hover state.

https://developer.mozilla.org/en-US/docs/Web/CSS/%3Ahover

i.fu.fu-parents:hover {
  background: image_url("icons/navigation/active/parents-active.svg");
}

By making this adjustment, you will achieve the desired result.

It would also be beneficial for you to expand your knowledge of HTML/CSS. Using a <ul> for navigation and having excessive class names can complicate maintenance and require additional work, such as adding role=presentation for screen readers. Consider taking this free online course to build a solid foundation:

Answer №2

It appears that you are trying to achieve a similar effect as demonstrated in this JSFiddle, am I correct?

a {color: red;}
ul{list-style-type: none;}
a:hover > i {color: blue;}

Answer №3

Even though I tried using CSS, I couldn't find a solution. However, I ended up using jQuery instead. This was because my images had two classes - one default and one active. Thank you for your help.

$("i").hover(
  function () {
    $(this).addClass('active');
  }, 
  function () {
    $(this).removeClass('active');
  }
  );

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

Eliminate Bootstrap's styling from HTML characters

The default heavy checkmark (✔) appears as "✔" Bootstrap 4.3 seems to be altering the appearance of the check, causing it to display as a thick-green one, which is not what I prefer -- see example below I want to remove Bootstrap's styli ...

Looking for assistance in turning this curl script into one that can handle multiple links

Below is a script that has the ability to download files from a given URL. However, I am looking for a way to include multiple links for downloading files. Instead of having a button to add another input box for URLs, I want users to be able to input three ...

What are the steps to changing the navbar's color when scrolling down?

I am having trouble changing the color of my navigation bar from transparent to black after the user scrolls down. Despite trying various methods and watching tutorials, I can't seem to get it to work. HTML <nav role='navigation' class= ...

What is the best way to retrieve the previously chosen item from an array?

I have successfully implemented dynamic pill tabs with one minor issue remaining. The most crucial aspect is that when I remove a pill, I want it to return to the previously opened tab. I have provided a StackBlitz example without routes on this page: -> ...

Tips for maintaining a sticky header while continuing to utilize Bootstrap table classes such as table-responsive and table-stripped

This is Here's my code on jsfiddle I've attempted to make the header sticky while maintaining the current layout, but every approach I've tried ends up messing with the responsiveness of the table. My next plan involves using a JavaScript ...

personalized options for initiating and concluding html audio component

I am currently facing an issue with my html audio element that plays a track. The setup is quite straightforward: <audio controls loop="loop"> <source type="audio/wav" src="song.wav"> </audio> However, I need to create custom start ...

Issue with login form in IONIC: Form only functions after page is refreshed

Encountering an issue with my Ionic login form where the submit button gets disabled due to invalid form even when it's not, or sometimes displays a console error stating form is invalid along with null inputs. This problem seems to have surfaced afte ...

Implementing custom styles in JavaScript according to the specific browser or platform

When it comes to adding multiple css styles to a dom element and ensuring compatibility across different browsers, which approach is more optimal for performance? Combining all prefixed css properties together, allowing the browser to decide which one ...

Vue.js V-for not rendering any content

I am currently working on populating an array with objects retrieved from an API. The objects are being fetched successfully, but I am facing issues when trying to display them using v-for in the array. Below are my data variables: data() { return { ...

Creating a moving background for a loading bar with HTML5 and Shadow DOM is currently underway

Can anyone help with animating the progress bar using the HTML5 <progess> tag? I've been able to customize the Shadow DOM elements successfully, but I'm having trouble animating the background (repeating linear gradient). It seems to work i ...

Maintaining the aspect ratio of images in Bootstrap Carousel: A complete guide

Using the default carousel from Bootstrap template has been working well for me. However, I've encountered an issue where resizing the browser window distorts the image aspect ratio by squishing it horizontally. I've tried various solutions to m ...

Previewing a PDF file with multiple headers displayed above the text content

Creating multiple headers for each page of a PDF document using dompdf can be tricky. The headers you generated are fixed at the top with a width of 100%. However, you are facing an issue where on the second and subsequent pages, the header overlaps with t ...

Converting plain text to HTML in emails using Outlook

Trying to figure out how to maintain the formatting of plain text email while displaying as virtual plain text in C sharp, specifically when receiving in Outlook 2007 with VSTO. The current code is not preserving the original formatting, instead it changes ...

Is there a way to incorporate a <u> tag into an inline angular variable in HTML that has been generated by a ternary expression?

Currently, I have the following scenario. <label> Make {{$ctrl.tcTemplate.isLibrary ? $ctrl.tcTemplate.name : "this item"}} a Library item: <toggle ng-change="changed(); $ctrl.eraseName();" ng-model="$ctrl.tcTemplate.isLibrary;" off="Fals ...

Utilizing Angular to apply multiple ng-repeat directives with multiple filters

I am working on a project that involves multiple ng-repeat lists with several filters. Currently, I am using (ex:A.value) if (ex:B.value), but I would like to implement multiple filters. The filters I want to incorporate are recommend_search, skill_searc ...

Tips for ensuring font-face displays correctly for every character

There seems to be a CSS clash that I cannot pinpoint on the site below: You can find the code snippet here: /*Font face settings for h3*/ @font-face { font-family: carrotflower; src: url('/wp-content/uploads/fonts/Carrotflower.eot') format(& ...

Is there a way to navigate through div text within a stationary container?

My current challenge involves a container that contains an overflow of text, but I desire for the container to remain fixed. The dilemma arises when the text spills out from both the top and bottom edges of the container. Instead of using scroll bars withi ...

Moving elements using CSS

Hi, I've been facing this issue with my web development since the start. Whenever I zoom in, the container also moves along. Is there any way to fix this problem? .darkslidecont{ width: 200px; height: 50px; position: relative; bac ...

Python Selenium error: NoSuchElementException - Unable to find the specified element

Coding Journey: With limited coding knowledge, I've attempted to learn through various resources without much success. Now, I'm taking a different approach by working on a project idea directly. The goal is to create a program that interacts wi ...

Is there a way to incorporate a base64 encoded image from a text file into an HTML image?

I have several images stored as base64 blobs in a remote location. Let's focus on one specific image: llorkcir.txt data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBxISEhASEBAQDxAQDw8QEA8PEA8PDw0PFRIWFhURFRUYHSggGBolGxUVITEhJSkrLi4uFx8zODMt ...