分享

css3实现鼠标移入图片动效

 头号码甲 2021-11-09

按照国际惯例先放效果图

贴代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>test</title>
    <style>
        .container{
            width:1200px;
            height:auto;
        }
        .container .img-box{
            overflow:hidden;
            position: relative;
            width:240px;
            height:135px;
            display: inline-block;
            cursor:pointer;

        }
        .container img{
            position: absolute;
            top:0;
            left:0;
            width:100%;
            height:100%;
            transition:all .5s;
        }        
        .container .overlay{
            position: absolute;
            width:100%;
            height:100%;
            top:0;
            left:0;
            z-index:2;
            line-height:135px;
            text-align: center;
            background-color: rgba(0,0,0,.5);
            opacity: 0;
        }
        .container .title{
            color:#fff;
        }
        .img-box:hover img{
            transform:scale(1.2);
        }
        .img-box:hover .overlay{
            opacity: 1;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="img-box">            
            <img src="images/1.jpg">
            <div class="overlay">
                <div class="title">图片标题1</div>
            </div>
        </div>
        <div class="img-box">            
            <img src="images/2.jpg">
            <div class="overlay">
                <div class="title">图片标题2</div>
            </div>
        </div>
    </div>
</body>
</html>

 

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多