首页 通知
看点 我的
  • 0
  • 0
  • 0
  • HTML+CSS带标题的图像悬停效果完整代码

  • 小小baby
  • 9
  • 2026-11-29
  • <!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="127.css">
    </head>
    
    <body>
        <div class="container">
            <div class="card">
                <img src="images/1.jpg" alt="">
                <div class="text">
                    <h2>A man <span>can't</span> ride your back unless it is bent</h2>
                    <p>你的腰不弯,别人就不能骑在你的背上。</p>
                </div>
            </div>
            <div class="card">
                <img src="images/2.jpg" alt="">
                <div class="text">
                    <h2>Wasting <span>time</span> is <span>robbing</span> oneself</h2>
                    <p>浪费时间就是掠夺自己。</p>
                </div>
            </div>
            <div class="card">
                <img src="images/3.jpg" alt="">
                <div class="text">
                    <h2>Conceit is the <span>quicksand</span> of success</h2>
                    <p>自负是成功的流沙。</p>
                </div>
            </div>
        </div>
    </body>
    
    </html>
    *{
        margin: 0;
        padding: 0;
    }
    body{
        height: 100vh;
        display: flex;
        justify-content: center;
        align-items: center;
        background-color: #212121;
    }
    .container{
        /* 弹性布局 允许换行 水平居中 */
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
    }
    .card{
        width: 310px;
        height: 220px;
        overflow: hidden;
        margin: 10px;
        background-color: #000;
        color: #fff;
        cursor: pointer;
        position: relative;
    }
    .card img{
        width: 100%;
        height: 100%;
        /* 设置过渡 */
        transition: 0.35s;
    }
    .card .text{
        position: absolute;
        top: 30px;
        left: 30px;
        bottom: 30px;
        right: 30px;
        padding: 0 18px;
    }
    .card .text::before{
        content: "";
        position: absolute;
        top: 0;
        bottom: 0;
        right: 0;
        left: 100%;
        border-left: 4px solid rgba(255,255,255,0.8);
        background-color: rgba(255,255,255,0.5);
        opacity: 0;
        /* 过渡 */
        transition: 0.5s;
        /* 过渡延迟时间 */
        transition-delay: 0.6s;
    }
    .card .text h2,
    .card .text p{
        margin-bottom: 6px;
        opacity: 0;
        transition: 0.35s;
    }
    .card .text h2{
        font-weight: 300;
        text-transform: uppercase;
        transform: translate(30%,0%);
        transition-delay: 0.3s;
    }
    .card .text h2 span{
        font-weight: 800;
    }
    .card .text p{
        font-weight: 200;
        transform: translate(0%,30%);
    }
    /* 悬停样式开始 */
    .card:hover img{
        opacity: 0.3;
    }
    .card:hover .text h2{
        opacity: 1;
        transform: translate(0%,0%);
        transition-delay: 0.4s;
    }
    .card:hover .text p{
        opacity: 0.9;
        transform: translate(0%,0%);
        transition-delay: 0.6s;
    }
    .card:hover .text::before{
        background-color: rgba(255,255,255,0);
        left: 0;
        opacity: 1;
        transition-delay: 0s;
    }


    评论

  • 0
    /1000
    最热
  • 最新
    • 0
    • 0
    • 0
    登录后参与评论