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

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

源码:
【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

你可能感兴趣的:(HTML5+CSS3小实例:创意条纹背景的图像悬停效果)