css样式实现鼠标移入图片文字上移

ps:
1.最外层盒子需设置相对定位,盒子里的元素设置绝对定位;
2.最外层盒子必须设置溢出隐藏overflow:hidden;
3.设置过渡时需要在hover里和div里都加上transition属性;
4.设置transition时为保证浏览器兼容需加上:-webkit-transition和-moz-transition;
4.设置鼠标移入事件时:hover正确书写方式,注意空格
正确#box:hover #div1;

<DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>demo</title>
<style type="text/css">
#box{
position:relative;
overflow:hidden;
width:500px;
height:300px;
margin:100px auto;
}
#img{
position:absolute;
width:100%;
height:100%;
bottom:0;
transition:bottom 2s  ease-in-out;
}
#div1{
position:absolute;
width:100%;
height:100%;
top:100%;
background-color:royalblue;
transition:all 2s  ease-in-out;
}
#box:hover #img{
bottom:100%;
}
#box:hover #div1{
top:0;
}
</style>
</head>
<body>
     <div id="box">
     <img id="img" src="images/1.png">
     <div id="div1">
     <h3>悯农</h3>
     <p>锄禾日当午,汗滴禾下土。</p>
     <p>谁知盘中餐,粒粒皆幸苦。</p>
     </div>
     </div>
</body>
</html>
  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值