Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

173
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda