Modifying the color of an icon upon hovering over the surrounding div container

I have a question regarding styling a div with a FontAwesome icon and text inside. I want the icon to remain white, but turn green when the mouse hovers over the root div. Any suggestions on how to achieve this?

The Component:

function GroceryItem({ title }) {
    return (
        <div className="root">
            <div className="row-content">
                <FontAwesomeIcon icon={faPlusSquare} className="add-icon"/>
                <p>{title}</p>  
            </div>
        </div>
    )
}

The styling:

.root {
  background-color: rgba(230, 230, 230);
  margin: 10px 0px;
}

.row-content {
  display: flex;
  padding: 15px;
}

.add-icon {
  color: whitesmoke;
}

I attempted to change the icon's color by using:

.root:hover {
  color: green
}

However, this only affects the text color and not the icon color.

Answer №2

If you're looking to specifically alter the color of the icon, this is a useful technique.

.root:hover svg {
  fill: green;
}

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

Tips for increasing a variable by one with each button click?

I have a simple JavaScript function called plusOne() that is designed to increment a variable by 1 each time a button is clicked, and then display the updated value on a webpage. However, I'm encountering an issue where the addition only occurs once. ...

How to stop cursor from changing on link click in Google Chrome

Have you ever noticed that when you click on a link in Chrome (but not Safari or Firefox), the cursor changes from pointer to arrow? Is there a way to prevent this behavior so that the pointer remains even after clicking, while still hovering over the link ...

ReactJS and Redux: Attempting to update the state of a React component that is unmounted is not possible

Check out this .gif recording showcasing the issue: After logging in, upon the initial load of my Dashboard component, an error is displayed in the console. Warning: Can't perform a React state update on an unmounted component. This is a no-op, but ...

What steps do I need to take in order to set up isomorphic-style-loader to load a node module

Having trouble with the react-draft-wysiwyg package as the styles it comes with are not applying properly. It seems like this issue stems from the way the imported css is loaded compared to how the class attributes of the module's elements work. Give ...

Header that stays in place even when there is too much content to fit horizontally

On my HTML page, I have a main header and body. Inside the body, there is another header and body that overflows horizontally. I want to ensure that no white space appears on the right side of both headers when the inner body scrollbar is moved right. Ins ...

Running and establishing a connection with a Google Cloud SQL database

I am in the process of developing a private website that will be hosted internally. My plan is to upload files to a Google Cloud bucket and then document specific information into a Cloud SQL database for future filtering purposes. While I have successful ...

Creating a fixed sidebar on the left and right using Bootstrap 5

Is it possible to create a left and right fixed sidebar with content in the middle using two <nav> elements in Bootstrap 5 markup structure? Here's an example of what I mean: <nav> <div>left sidebar</div> </nav> <mai ...

My eCommerce website is currently experiencing some technical difficulties that need to be addressed

I'm in need of assistance with a particular error I encountered. I was following an ecommerce example application and everything seemed to be going smoothly until I clicked on "Shop Now." At that point, I received the following message: Server Error T ...

Develop a custom ButtonGroup component in mui react, which utilizes props.children for enhanced

When using the Buttongroup component, I am trying to include multiple buttons inside it. However, I am currently only able to display one button. How can I loop or add multiple buttons within the Buttongroup Component? Any assistance would be greatly app ...

Refreshing the page in Next.js causes issues with the CSS classNames

I am currently in the process of migrating a React SPA to Next.js, and I am relatively new to this framework. The issue I am encountering is that when I initially load the Home page, everything appears as expected. However, if I refresh the page, incorrect ...

Ensure that the divs are properly aligned and construct columns within a single column

I've been working on creating a step bar that needs to adapt to any number of steps provided by the backend. Here's what I have so far: https://i.sstatic.net/cj4qZ.png It looks fine, but connecting the circles with bars would be beneficial. How ...

Guide to rendering a menu using recursion

Currently, I am attempting to render the AntDesign Menu component recursively. While there are examples available for rendering with standard ul and li tags, when I try to switch to using Menu.Item and SubMenu, all items become active with incorrect styles ...

What is the best way to create a sticky/fixed navbar that conceals the div above it while scrolling on the page?

When I am at the top of the page, I want to display the phone number and email above the navigation bar. However, as soon as I start scrolling down, I want the phone number and email to disappear and only show the navigation bar. I have attempted using fix ...

Calculating the number of characters in a textarea upon the initialization of a component

Exploring the world of react, I encountered a simple application with just two pages: Home and Details. Upon transitioning from the Home page to the Details page, I stumbled upon a character count feature pertaining to a textarea. Both components are in fu ...

Delete the display:none; attribute to make the item appear on the screen

The following CSS code styles the element: span { position:absolute; float:left; height:80px; width:150px; top:210px; left:320px; background-color:yellow; display:none; //No display ...

Dealing with user context upon logout regarding the user's admin status in ReactJs / Error: Unable to determine user as it is

I am currently working on implementing a feature in my ReactJS (MERN) application, where the navbar link to '/admin' is only visible if the user.isAdmin property is true. The snippet of my navbar code looks like this: Navbar import { useAuthCon ...

Using Angular TypeScript to create dynamic CSS animations

Looking to incorporate CSS animations into a function. When the timer reaches its end, it triggers a snack bar message and I want the color of the timer text to shift from white to red as a warning signal. Currently, I have managed to turn it red at the ...

Attempting to align the dropdown menu to the left side

This is a challenge I'm facing: https://i.sstatic.net/d3PtN.png I'm attempting to align it in the following way: https://i.sstatic.net/GCwEO.png Below is the HTML code snippet: <li class='list-group-item'> <!-- The dropdow ...

Is there any difference between props.render and props.children?

I'm struggling to differentiate between props.render and props.children. It seems like they may serve a similar purpose but go about it in unique ways. Can someone clarify if my understanding is correct? If not, could you explain the differences betw ...

How about trying out some dropdowns?

Following the issue I mentioned in my previous question titled Margin-Right on CSS not working, I am currently engaged in a creative endeavor to redesign my school's website homepage. The progress so far has been significant, but I now require some as ...