Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

175
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda