zzy
CSS练习

CSS练习


        

3d卡片的移入效果

example

   


       
       
       
   

项目结构:

  • index.html
  • style.css
  • assets
    • cover.jpg
    • yui.png
    • title.png

代码:

  1. index.html

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Hirasawa Yui</title>
    <link rel="stylesheet" href="./style.css">
    </head>
    <body>
    <div class="card">
    <img src="./assets/cover.jpg" class="cover">
    <img src="./assets/title.png" class="title">
    <img src="./assets/yui.png" class="yui">
    </div>
    </body>
    </html>
  2. style.css

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    body {
    align-items: center;
    }
    .card {
    width: 200px;
    height: 300px;
    margin: 0 200px;
    transform: translateX(200px) translateY(200px);
    position: relative;
    }
    .card img {
    width: 100%;
    position: absolute;
    transition: 0.5s;
    }
    .card .cover {
    z-index: 1;
    }
    .card:hover .cover {
    box-shadow: 0 35px 35px -8px rgba(0, 0, 0, 0.75);
    transform: perspective(500px) rotateX(25deg);
    opacity: 0.7;
    }
    .card .yui {
    z-index: 2;
    opacity: 0;
    transform: translateY(20%);
    }
    .card:hover .yui {
    opacity: 1;
    transform: perspective(500px) translate3d(0, -10px, 50px);
    }
    .card .title {
    z-index: 3;
    bottom: 0;
    }
    .card:hover .title {
    transform: perspective(500px) translate3d(0, -25px, 50px);
    }
本文作者:zzy
本文链接:http://周梓煜.com/2024/07/26/css/
版权声明:本文采用 CC BY-NC-SA 3.0 CN 协议进行许可