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

251
Vistas
¿Cómo hago para que cuando pase el mouse sobre mi texto cambie de color y el color permanezca cambiado?

Soy nuevo en el desarrollo web y parece que no puedo descifrar cómo cambiar el color de mi texto cuando lo desplazo y hacer que permanezca cambiado. Actualmente tengo esto:

 .main{ color: white; font-size: 20px; } .main:hover{ animation: textchange 1s cubic-bezier(0.165, 0.84, 0.44, 1); } @keyframes textchange{ from{ color: white; } to { color:black; } }
 <p class=main> Lorem ipsum dolor sit amet </p>

Entiendo por qué el color no se mantiene negro después de no pasar el cursor, pero todavía no sé cómo abordar esto. Ni siquiera estoy seguro de si esto es posible sin javascript.

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

Debes usar animation-fill-mode: forwards;

 function enter() { const main = document.getElementById('main-with-javascript'); main.style.animation = 'textchange 4s cubic-bezier(0.165, 0.84, 0.44, 1)'; main.style.animationFillMode = 'forwards'; } function leave() { const main = document.getElementById('main-with-javascript'); main.style.animation = 'textchangeReverse 4s cubic-bezier(0.165, 0.84, 0.44, 1)'; }
 #main-with-javascript { color: #dddddd; font-size: 20px; } .main { color: #dddddd; font-size: 20px; animation: textchangeReverse 4s cubic-bezier(0.165, 0.84, 0.44, 1); animation-fill-mode: forwards; } .main:hover { animation: textchange 4s cubic-bezier(0.165, 0.84, 0.44, 1); /*Let the element retain the style values from the last keyframe when the animation ends*/ animation-fill-mode: forwards; } @keyframes textchange { from { color: #dddddd; } to { color: black; } } @keyframes textchangeReverse { from { color: black; } to { color: #dddddd; } }
 <h2>with css</h2> <p class='main'> Lorem ipsum dolor sit amet </p> <hr/> <h2>with css and javasctipt</h2> <p id='main-with-javascript' onmouseenter='enter()' onmouseleave='leave()'> Lorem ipsum dolor sit amet </p>

about 4 years ago · Juan Pablo Isaza Denunciar

0

Agregue esto a css pero

 p.black { color: black; }

Necesitas usar javascript para eso

 document.querySelector(".main").addEventListener("mouseover", function(e) { this.classList.add("black"); })
about 4 years ago · Juan Pablo Isaza Denunciar

0

 .main{ color: rgb(206, 37, 37); font-size: 20px; } .main:hover{ animation-name: textchange; animation-duration: 1s; animation-iteration-count: infinite; } @keyframes textchange{ 0%{ color: rgb(0, 0, 0); } 100%{ color:black; } }
 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <link rel="stylesheet" href="github.css"> </head> <body> <main> <p class=main> Lorem ipsum dolor sit amet </p> </main> </body> </html>

Debe configurar el recuento de iteraciones de la animación en infinito y dentro de los fotogramas clave para 0% configure el color en negro y para 100% configure el color negro también.

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