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

254
Views
¿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 answers
Answer question

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 Report

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 Report

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 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!