<html>
<head>
<style>
div{
width:100px
height:100px
border:1px solid black
position:absolute
}
#ddd{
background-color:blue
}
#df
{
background-color:red
animation:mymove 1s infinite
-webkit-animation:mymove 1s infinite /*Safari and Chrome*/
}
@keyframes mymove
{
from {opacity:0}
to {opacity:1}
}
@-webkit-keyframes mymove /*Safari and Chrome*/
{
from {opacity:none}
to {opacity:block}
}
</style>
</head>
<body>
<div id="ddd"></div>
<div id="df"></div>
</body>
</html>
方法有很多种,下面我介绍一种纯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>