css3动画怎样能从下往上慢慢升上去 代码怎么写

html-css012

css3动画怎样能从下往上慢慢升上去 代码怎么写,第1张

<!DOCTYPE html>

<html>

<head>

    <style>

        div

        {

            width:100px

            height:100px

            background:red

            position:absolute

            animation:myfirst 5s

            -webkit-animation:myfirst 5s

            animation-fill-mode: forwards

        }

        @-webkit-keyframes myfirst /* Safari and Chrome */

        {

            0%   {background:red left:500px bottom:50px}

            25%  {background:red left:500pxheight:130pxbottom:50px}

            50%  {background:red left:500px height:160pxbottom:50px}

            75%  {background:red left:500pxheight:190px bottom:50px}

            100% {background:red left:500px height:210pxbottom:50px}

        }

    </style>

</head>

<body>

<div></div>

</body>

</html>

这只是个演示的demo,方法就是这样,animation-fill-mode: forwards这一句给你解释下,这句就是当动画完成时,动画会停留在最后一帧。其他代码都比较简单,不懂随时问我。

希望能够帮助到你,望采纳!

方法有很多种,下面我介绍一种纯CSS的实现的方式:

<!DOCTYPE html>

<html lang="zh-cn">

<head>

<meta charset="utf-8" />

<title></title>

<style>

html,

body {

margin: 0

padding: 0

}

.main {

width: 460px/*每个box的宽度为150px,间隔为5*2*/

margin: 0 auto

}

.demo {

float: left

display: inline-block

}

.box {

height: 150px

width: 150px

background: #3695d5

position: relative

overflow: hidden

}

.inbox {

height: 50px

line-height: 50px

text-align: center

color: #FFF

width: 100%

position: absolute

bottom: -50px

background: rgba(0, 0, 0, 0.3)

transition: 1s/*过渡效果*/

}

.box:hover>.inbox {

bottom: 0

}

</style>

</head>

<body>

<div class="main">

<div class="demo">

<div class="box">

图片

<div class="inbox">

文字

</div>

</div>

</div>

<div class="demo" style="margin: 0 5px 0 5px">

<div class="box">

图片

<div class="inbox">

文字

</div>

</div>

</div>

<div class="demo">

<div class="box">

图片

<div class="inbox">

文字

</div>

</div>

</div>

</div>

</body>

</script>

</html>