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

148
Visualizações
why inline styling &:hover will not have any effect in react js

I'm trying to add hover effect to a span element as shown below.

  • Hover effect doesn't work when added inside style prop.
  • But, If it is written in separate css file it will work

I just want to know, Why it is So?

enter image description here

https://codesandbox.io/s/happy-resonance-stqbf9?file=/src/App.js

App.js

import "./styles.css";

export default function App() {
  return (
    <div className="App">
      <span
        style={{
          fontSize: "4em",
          color: "blue",
          "&:hover": {
            color: "green"
          }
        }}
      >
        Element
      </span>
      <div></div>
      <span className="ele">Element 2</span>
    </div>
  );
}

styles.css

.App {
  font-family: sans-serif;
  text-align: center;
}

.ele {
  font-size: 4em;
  color: blue;
}

.ele:hover {
  font-size: 6em;
  color: green;
}
about 4 years ago · Santiago Gelvez
2 Respostas
Responde à pergunta

0

That because we can't specify the inline styles for pseudo elements and pseudo classes. You can use it with the,

  1. Internal - by using a <style> element in the section.

An internal CSS is defined in the section of an HTML page, within a element.example

  1. External - by using a element to link to an external CSS file To use an external style sheet, add a link to it in the section of each HTML page.example
about 4 years ago · Santiago Gelvez Relatório

0

You need to use JSS Plugin which supports the psudo-selectors inline style, or you should use Material UI, which also support this plugin.

about 4 years ago · Santiago Gelvez 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