前端使用css3实现人物卡片介绍动画

前端使用css3实现人物卡片介绍动画,鼠标移入后图片缩小现实出人物简介文字,鼠标移出再恢复。

在这里插入图片描述
在这里插入图片描述

<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>人物介绍卡片</title>
<style>
       *{
    
    
            margin: 0;
            padding: 0;
        }
       body{
    
    
            /* 弹性布局 让页面元素水平+垂直居中*/
            display: flex;
            justify-content: center;
            align-items: center;
            /*让页面始终占浏览器总高*/
            height: 100vh;
            background:linear-gradient(200deg,#517fa4,#243949);
        }
        .card{
    
    
             position: relative;
             width: 300px;
             height: 450px;
             margin: 20px;
             background-color: #758a99;
             border-radius: 20px;
             overflow: hidden;
             display: flex;
             /* 元素纵向排列*/
             flex-direction: column;
             align-items: center;
             color: #fff;
             box-shadow: 0 0 30px rgba(0,0,0,0.5);
             /* 不让其被挤压*/
             flex-shrink: 0;
        }
        .card .photo img{
    
    
             width: 100%;
             height: 100%;
             /* 保持原有尺寸比例,裁切长边*/
             object-fit: cover;
        }
        /* 默认大图 */
        .card .photo{
    
    
             position: absolute;
             top: 0;
             width: 100%;
             height: 100%;
             border-radius: 0%;
             overflow: hidden;
             transition: 0.5s;
        }
        /* 鼠标移入变小图 */
        .card:hover .photo{
    
    
             top:30px;
             width: 120px;
             height: 120px;
             border-radius: 50%;
             box-shadow: 0 0 20px rgba(0,0,0,0.8);
        }
        /*加一个黑色到透明的渐变背景,可以更清楚的看到名字*/
        .card .photo::before{
    
    
             content:"";
             position: absolute;
             width: 100%;
             height: 100%;
             background: linear-gradient(to bottom,transparent 50%,#222);
        }
        .card h1{
    
    
             position: absolute;
             top:370px;
             transition: 0.5s;
        }
        .card:hover h1{
    
    
             top:170px
        }
        .card h2{
    
    
             margin-top: 220px;
             width: 80%;
             border-bottom: 1px solid rgba(245, 255, 255, 0.3);
             font-size: 20px;
             text-align: center;
             margin-bottom: 20px;
             padding-bottom:20px ;
        }
        .card p{
    
    
             width: 90%;
             text-indent: 32px;
             font-size: 16px;
             margin-bottom: 15px;
             line-height: 30px;
        }
        .card a{
    
    
             font-size: 14px;
             color:rgba(255,255,255,0.8);
             text-decoration:none ;
             border:1px solid rgba(255,255,255,0.5);
             padding:8px 32px;
             border-radius: 8px;
        }
</style>
</head>
<body>
     <div class="card">
          <div class="photo"><img src='./img/6.jpeg' alt=""/></div>
          <h1>六道仙人 班</h1>
          <h2>火影忍者</h2>
          <p>火影忍者第三次忍界大战,火之国联合其他四国一起对抗以班为首的晓组织成员的战斗</p>
          <a href="#">了解更多</a>
     </div>
     <div class="card">
          <div class="photo"><img src='./img/4.jpeg' alt=""/></div>
          <h1>宇智波 佐助</h1>
          <h2>火影忍者</h2>
          <p>火影忍者第三次忍界大战,火之国联合其他四国一起对抗以班为首的晓组织成员的战斗</p>
          <a href="#">了解更多</a>
     </div>
     <div class="card">
          <div class="photo"><img src='./img/5.jpeg' alt=""/></div>
          <h1>宇智波 班</h1>
          <h2>火影忍者</h2>
          <p>火影忍者第三次忍界大战,火之国联合其他四国一起对抗以班为首的晓组织成员的战斗</p>
          <a href="#">了解更多</a>
     </div>
</body>
</html>




猜你喜欢

转载自blog.csdn.net/m0_46577631/article/details/127966163