I have a parent div and two child divs, I want to apply CSS to the second child div when I hover on the first child div. This is the structure of the render method.
JavaScript
x
5
1
<div className={classes.parent}>
2
<div className={classes.child1}></div>
3
<div className={classes.child2}></div>
4
</div>
5
What is the material UI’s makeStyles syntax for selecting child classes on hover?
Advertisement
Answer
You can use element+element
selector to select the element after the current element:
JavaScript
1
15
15
1
const useStyles = makeStyles({
2
parent: {
3
//
4
},
5
child1: {
6
"&:hover + *": {
7
// change the background color of child-2 when hovering on child-1
8
backgroundColor: "red"
9
}
10
},
11
child2: {
12
//
13
}
14
});
15