Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slide in from left CSS animation

I would like to make a simple animation, when the page loads, my logo should animate from the left side of the box to the right side. I have tried many versions, but haven't succeeded yet.

HTML

<body>

<div>
<img src="logo.png" alt="logo" style="width:170px;height:120px;">
</div>
</body>

CSS

div
{
 width:640px;
 height:175px;
 background:blue;
 -webkit-transition: all 1s ease-in-out;
 -moz-transition: all 1s ease-in-out;
 -o-transition: all 1s ease-in-out;
 -ms-transition: all 1s ease-in-out;
 position:absolute;
}
div img
{
 -webkit-transform: translate(3em,0);
 -moz-transform: translate(3em,0);
 -o-transform: translate(3em,0);
 -ms-transform: translate(3em,0);
}
like image 522
user2165458 Avatar asked Dec 08 '15 15:12

user2165458


People also ask

How do you add a transition to the left in CSS?

In CSS, for slide-in from left transition, the “transition-property” is used. You can set the effect of transition and its duration using the “transition-property” and “transition-duration” properties, respectively.

Can you do inline CSS animations?

You can't animate inline elements Even though some browsers can animate inline elements, this goes against the CSS animation specs and will break on some browsers or eventually cease to work.


1 Answers

Try using keyframes.

div {
  width: 50px;
  height: 40px;
  background: blue;
  position: relative;
  left: 500px;
  -webkit-animation: slideIn 2s forwards;
  -moz-animation: slideIn 2s forwards;
  animation: slideIn 2s forwards;
}
@-webkit-keyframes slideIn {
  0% {
    transform: translateX(-900px);
  }
  100% {
    transform: translateX(0);
  }
}
@-moz-keyframes slideIn {
  0% {
    transform: translateX(-900px);
  }
  100% {
    transform: translateX(0);
  }
}
@keyframes slideIn {
  0% {
    transform: translateX(-900px);
  }
  100% {
    transform: translateX(0);
  }
}
<div></div>
like image 153
Aaron Avatar answered Oct 08 '22 15:10

Aaron