动画不起作用。从左:0px移动到左:200px

时间:2019-05-24 15:55:34

标签: html css3 animation css-animations

我是html5和css3的新手,我只是在玩不同的css3动画功能。谁能在下面的代码中指出错误?从左0像素到左200像素的移动不起作用。

<!doctype html>
<html>
    <head>
    <title>
        Experiment: animation with movements
    </title>

    <style>
        footer{
            width: 100px;
            height: 100px;
            background: red;
            animation: mymove 5s;
            animation-play-state: running;
        }

        @-moz-keyframes mymove {
            from {left:50px;}
            to {left:200px;}
        }
        @keyframes mymove {
            from {left:50px;}
            to {left:200px;}
        }
    </style>
</head>
<body>

<footer>
</footer>

</body>
</html>

1 个答案:

答案 0 :(得分:0)

position: relative;添加到footer CSS

footer {
  position: relative;
  width: 100px;
  height: 100px;
  background: red;
  animation: mymove 5s;
  animation-play-state: running;
}

@-moz-keyframes mymove {
  from {
    left: 50px;
  }
  to {
    left: 200px;
  }
}

@keyframes mymove {
  from {
    left: 50px;
  }
  to {
    left: 200px;
  }
}
<footer></footer>