HTML5+CSS3小实例:创意条纹背景的图像悬停效果

实例:创意条纹背景的图像悬停效果
技术栈:HTML+CSS
效果:

源码:
【html】

<!DOCTYPE html>
<html>
 
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
 
    <title>创意条纹背景的图像悬停效果</title>
    <link rel="stylesheet" href="../css/98.css">
</head>
 
<body>
    <div class="container">
        <div class="box">
            <img src="../images/male.png" alt="">
        </div>
        <div class="box">
            <img src="../images/female.png" alt="">
        </div>
    </div>
</body>
 
</html>

【css】

*{
    /* 初始化 */
    margin: 0;
    padding: 0;
}
body{
    /* 100%窗口高度 */
    min-height: 100vh;
    /* 弹性布局 水平+垂直居中 */
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #333;
}
.container{
    display: flex;
    /* 倒影 */
    -webkit-box-reflect: below 2px linear-gradient(transparent 60%,rgba(0,0,0,0.2));
}
.container .box{
    /* 相对定位 */
    position: relative;
    /* 弹性布局 水平居中 */
    display: flex;
    justify-content: center;
    width: 320px;
    height: 400px;
    margin: 0 20px;
    border-radius: 20px;
    /* 条纹背景 */
    background: linear-gradient(45deg,#c7cc97 25%,#444 25%,#444 50%,#c7cc97 50%,#c7cc97 75%,#444 75%,#444 100%);
    background-size: 40px 40px;
    /* 灰度滤镜 */
    filter: grayscale(1);
    /* 执行动画: 动画名 时长 线性的 无限次播放 */
    animation: animateBg 0.5s linear infinite;
    /* 默认动画状态为暂停 */
    animation-play-state: paused;
    /* 设置灰度滤镜的过渡时间为1秒 */
    transition: filter 1s;
}
/* 改变第二个卡片的背景条纹颜色 */
.container .box:nth-child(2){
    background: linear-gradient(135deg,#e6a28c 25%,#444 25%,#444 50%,#e6a28c 50%,#e6a28c 75%,#444 75%,#444 100%);
    background-size: 40px 40px;
}
.container .box img{
    /* 绝对定位 */
    position: absolute;
    bottom: 0;
    height: 90%;
    /* 设置过渡 */
    transition: 0.5s;
}
.container .box:hover{
    /* 鼠标移入, 灰度无效, 动画播放 */
    filter: grayscale(0);
    animation-play-state: running;
}
.container .box:hover img{
    /* 鼠标移入, 图片变大 */
    height: 480px;
}
 
/* 定义动画 */
@keyframes animateBg {
    0%{
        background-position: 0;
    }
    100%{
        background-position: 40px;
    }
}

【图片素材】
https://www.aliyundrive.com/s/q9UyoG8tx7W
https://www.aliyundrive.com/s/2rpCpyKCV59

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容