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

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

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 Relatório

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 Relatório

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