2

I have a div that consists of a FontAwesome icon and some text. I'd like to keep the white colour of the icon and change it to green when the pointer is hovering on top of the root div. How can I do 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 thought I'd be able to change colour of the icon if I set:

.root:hover {
  color: green
}

But doing this only changes the colour of the text, and not the colour of the icon.

0

2 Answers 2

3

Use a descendent selector, select all descendents.

.root:hover * {
  color: green
}

Edit how-to-change-icon-colour-when-hovering-on-enclosing-div-container

0

This would help if you want to change color of the icon only

.root:hover svg {
  fill: green;
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.