Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

170
Views
How to style a child element when its parent element is hovered on (js stylesheet)

I have a js style file with a notification component that has its own class. It contains a viewDot div with its own separate class in the same file that is present when the notification hasn't been clicked on yet. The viewDot div is inside of the div that has the notificationStyle class.

I want to make it so that if I hover over the notification with a cursor, the color of the viewDot also changes. As it is below, the color of the viewDot only changes if I hover directly on the viewDot. Any tips on accomplishing the described behavior are greatly appreciated

const styles = theme => ({
    viewDot: {
        backgroundColor: '#00B8C4',
        '&:hover': {
            backgroundColor: '#F9D967',
        }
    },
    notificationStyle: {
        backgroundColor: '#FFFFFF',
        '&:hover': {
            backgroundColor: '#52B5C2',
        },
        // want to do something like this, but this is not correct as is
        '&:hover .viewDot': {
            backgroundColor: '#F9D967'
        }
    },
});

The variable styles is imported from this ComponentStyles.js file to a Component.jsx file for a Component using the file path and the styles are made using const useStyles = makeStyles(styles); before the code block for the component. In the code block for the component, I use const classes = useStyles(); in order to use something like className={ classes.notificationStyle } for the elements inside the component.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Change the '&hover.viewDot to '&:hover .viewDot.

The hover requires a : since it is a pseudo-class, and you need a space between the two classnames since you want to specify a descendant relation


Update

Seeing that you use MUI and JSS, the names in theme are not actually converted to class names and that is why '&:hover .viewDot' did not work.

The correct syntax to reference another style defined in the same scope is to use $ruleName, so in this case '&:hover $viewDot'

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!