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

81
Vistas
transition with right using css?

I'm trying to make a box slide from left to right using only transition like this:

#box {
  width: 150px;
  height: 150px;
  background: red;
  position:absolute;
  transition: all 2s ease-out;
  right:auto;

}

.active{
  background-color: green !important;
  right:0 !important;
}
<div id="box" onclick="this.classList.add('active')"></div>

but for some reason the box doesn't slide to the right

This solution works but there is no explanation to it
can someone please explain why the background color transitions but not the right position?

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

0

you have to specify the 'right' property for the box in px or in %, instead of 'auto'.

#box {
  width: 150px;
  height: 150px;
  background: red;
  position:absolute;
  transition: all 2s ease-out;
  right:calc(100% - 150px);   /* right is positioned to left by reducing the actual box width */

}

.active{
  background-color: green !important;
  right:0 !important;
}
<div id="box" onclick="this.classList.add('active')"></div>

about 4 years ago · Juan Pablo Isaza Denunciar

0

Using right: auto; does not work.

#box {
  width: 150px;
  height: 150px;
  background: red;
  position:absolute;
  transition: all 2s ease-out;
  right:100%;
  transform: translate(100%,0);

}

.active{
  background-color: green !important;
  right:0 !important;
  transform: translate(0,0) !important;
}
<div id="box" onclick="this.classList.add('active')"></div>

about 4 years ago · Juan Pablo Isaza Denunciar

0

Try using animation instead and add keyframes as in snippet below.

#box {
  width: 150px;
  height: 150px;
  background: red;
  position:absolute;
  animation: slide 2s forwards ease-out;
  right:auto;

}

  @keyframes slide {
    0% {
        transform: translateX(0);
    }
    100% {
        transform: translateX(50%);
    }
}
 <div id="box"></div>

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