使用CSS怎么实现一个图片动画特效

发布时间:2021-04-07 17:31:44 作者:Leah
来源:亿速云 阅读:401

本篇文章给大家分享的是有关使用CSS怎么实现一个图片动画特效,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。

HTML代码

<!-- 主容器 -->
<div class="box">

    <!-- 图片 -->
    <img src="images/pic.png" alt=""/>

    <!-- 内容 -->
    <div class="box-inner-content">
        <h4 class="title">Rabbit</h4>
    <span class="post">Web Developer</span>
    </div>

</div>

CSS代码

/* 初始化 */
body,
html {
    font-size: 100%;
}
* {
    padding: 0;
    margin: 0;
    box-sizing: border-box;
}
body {
    background: #494A5F;
    font-weight: 500;
    font-size: 1.05em;
    font-family: "Microsoft YaHei","Segoe UI", "Lucida Grande", Helvetica, Arial,sans-serif;
}

/* 外层容器 */
.box {
    margin: 100px auto;
    width: 400px;
    height: 400px;
    overflow: hidden;
    position: relative;
}
.box:before {
    content: "";
    display: block;
    border: 30px solid rgba(255, 255, 255, 0.3);
    position: absolute;
    top: 5px;
    left: 5px;
    bottom: 5px;
    right: 5px;
    opacity: 1;
    z-index: 2;
    transition: all 0.3s ease 0s;
}
.box:hover:before {
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border: 10px solid rgba(255, 255, 255, 0.18);
}
.box:after {
    content: "";
    display: block;
    border: 8px solid #fff;
    position: absolute;
    top: 35px;
    left: 35px;
    bottom: 35px;
    right: 35px;
    opacity: 1;
    z-index: 1;
    transition: all 0.5s ease 0s;
}
.box:hover:after {
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    opacity: 0;
}

/* 图片 */
.box img {
    width: 100%;
    height: auto;
    transform: scale(1.2);
    transition: all 0.5s ease 0s;
}
.box:hover img {
    transform: scale(1);
}

/* 文字内容 */
.box .box-inner-content {
    position: absolute;
    left: 45px;
    bottom: 125px;
    right: 45px;
    text-align: center;
    color: #fff;
    opacity: 0;
    transition: all 0.3s ease 0s;
}
.box:hover .box-inner-content {
    opacity: 1;
    bottom: 20px;
    text-shadow: 0 0 10px #000;
}

/* 标题 */
.box .title {
    font-size: 26px;
    font-weight: bold;
    margin: 0;
}

/* 文本 */
.box .post{
    display: block;
    font-size: 16px;
    font-style: italic;
    margin-bottom: 10px;
}

以上就是使用CSS怎么实现一个图片动画特效,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注亿速云行业资讯频道。

推荐阅读:
  1. CSS3如何实现loading预加载动画特效
  2. CSS3中怎么实现单选框动画特效

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

css

上一篇:如何在CentOS7.2服务器中搭建一个Docker私有镜像仓库

下一篇:如何在MySQL数据库中优化insert的性能

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》